Browse code

Fix default article layout implementation

Benjamin Roth authored on27/06/2017 16:07:36
Showing1 changed files
... ...
@@ -156,6 +156,31 @@ class tl_article_eSM_artLayout extends \Backend
156 156
    */
157 157
   public function setDefaultLayout(\DataContainer $dc)
158 158
   {
159
+    if ($_GET['act'] == 'create') {
160
+      if ($_GET['mode'] == 1)
161
+      {
162
+        $ArticleModel = \ArticleModel::findByPk($_GET['pid']);
163
+        if ($ArticleModel !== null)
164
+        {
165
+          $PageModel = $ArticleModel->getRelated('pid');
166
+          $PageModel->loadDetails();
167
+        }
168
+      } else if ($_GET['mode'] == 2)
169
+      {
170
+        $PageModel = \PageModel::findWithDetails($_GET['pid']);
171
+      }
172
+
173
+      if ($PageModel !== null)
174
+      {
175
+        $LayoutModel = \LayoutModel::findByPk($PageModel->layout);
176
+        $ArticleDefaultLayout = \Database::getInstance()->prepare("SELECT al.id FROM tl_article_layouts al, tl_theme t WHERE t.id = al.pid AND isDefault = '1' AND al.pid = ? ORDER BY t.name, al.sorting LIMIT 1")->execute($LayoutModel->pid);
177
+
178
+        if ($ArticleDefaultLayout->numRows)
179
+        {
180
+          $GLOBALS['TL_DCA']['tl_article']['fields']['es_type']['default'] = $ArticleDefaultLayout->id;
181
+        }
182
+      }
183
+    }
159 184
     if ($_GET['act'] == 'edit')
160 185
     {
161 186
       $ArticleModel = \ArticleModel::findByPk($dc->id);
... ...
@@ -170,12 +195,13 @@ class tl_article_eSM_artLayout extends \Backend
170 195
 
171 196
           if ($PageModel !== null)
172 197
           {
173
-            $ArticleDefaultLayout = \Database::getInstance()->prepare("SELECT al.id FROM tl_article_layouts al, tl_theme t WHERE t.id = al.pid AND isDefault = '1' AND al.pid = ? ORDER BY t.name, al.sorting LIMIT 1")->execute($LayoutModel->id);
198
+            $ArticleDefaultLayout = \Database::getInstance()->prepare("SELECT al.id FROM tl_article_layouts al, tl_theme t WHERE t.id = al.pid AND isDefault = '1' AND al.pid = ? ORDER BY t.name, al.sorting LIMIT 1")->execute($LayoutModel->pid);
174 199
 
175 200
             if ($ArticleDefaultLayout->numRows)
176 201
             {
177 202
               $ArticleModel->es_type = $ArticleDefaultLayout->id;
178 203
               $ArticleModel->save();
204
+              $this->reload();
179 205
             }
180 206
           }
181 207
         }