... | ... |
@@ -13,6 +13,7 @@ |
13 | 13 |
* Callbacks |
14 | 14 |
*/ |
15 | 15 |
$GLOBALS['TL_DCA']['tl_content']['fields']['type']['options_callback'] = array('tl_content_eSM_artLayout','getContentElements'); |
16 |
+$GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'][] = array('tl_content_eSM_artLayout','setDefault'); |
|
16 | 17 |
|
17 | 18 |
|
18 | 19 |
/** |
... | ... |
@@ -91,4 +92,46 @@ class tl_content_eSM_artLayout extends \Backend |
91 | 92 |
|
92 | 93 |
return $groups; |
93 | 94 |
} |
95 |
+ |
|
96 |
+ /** |
|
97 |
+ * Set default type value |
|
98 |
+ * |
|
99 |
+ * @param DataContainer $dc |
|
100 |
+ */ |
|
101 |
+ public function setDefault(\DataContainer $dc) |
|
102 |
+ { |
|
103 |
+ if ($_GET['act'] == 'edit') |
|
104 |
+ { |
|
105 |
+ $ContentElement = \ContentModel::findByPk($dc->id); |
|
106 |
+ |
|
107 |
+ if ($ContentElement !== null) |
|
108 |
+ { |
|
109 |
+ |
|
110 |
+ $dc->activeRecord = $ContentElement; |
|
111 |
+ $arrGroups = $this->getContentElements($dc); |
|
112 |
+ |
|
113 |
+ if (count($arrGroups)) |
|
114 |
+ { |
|
115 |
+ $blnDefaultAvailable = false; |
|
116 |
+ |
|
117 |
+ foreach ($arrGroups as $k => $v) |
|
118 |
+ { |
|
119 |
+ if (in_array($ContentElement->type, $v)) |
|
120 |
+ { |
|
121 |
+ $blnDefaultAvailable = true; |
|
122 |
+ } |
|
123 |
+ } |
|
124 |
+ |
|
125 |
+ if (!$blnDefaultAvailable) |
|
126 |
+ { |
|
127 |
+ $varValue = reset(reset($arrGroups)); |
|
128 |
+ |
|
129 |
+ \Database::getInstance()->prepare("UPDATE tl_content SET type = ? WHERE id = ?")->execute($varValue,$dc->id); |
|
130 |
+ $this->reload(); |
|
131 |
+ } |
|
132 |
+ } |
|
133 |
+ } |
|
134 |
+ } |
|
135 |
+ } |
|
136 |
+ |
|
94 | 137 |
} |
95 | 138 |
\ No newline at end of file |