Browse code

Sanitize the code, adjust the usage of namespaces and add some comments

Benjamin Roth authored on13/07/2016 10:34:22
Showing1 changed files
... ...
@@ -71,7 +71,7 @@ $GLOBALS['TL_DCA']['tl_article']['fields']['es_size'] = array
71 71
  *
72 72
  * @author Benjamin Roth <http://www.esales-media.de>
73 73
  */
74
-class tl_article_eSM_artLayout extends Backend
74
+class tl_article_eSM_artLayout extends \Backend
75 75
 {
76 76
 
77 77
   /**
... ...
@@ -83,6 +83,13 @@ class tl_article_eSM_artLayout extends Backend
83 83
     $this->import('BackendUser', 'User');
84 84
   }
85 85
 
86
+  /**
87
+   * Return article layouts
88
+   *
89
+   * @param DataContainer $dc
90
+   *
91
+   * @return array
92
+   */
86 93
   public function getArticleLayouts(\DataContainer $dc)
87 94
   {
88 95
 
... ...
@@ -97,6 +104,11 @@ class tl_article_eSM_artLayout extends Backend
97 104
     return $arrArticleLayouts;
98 105
   }
99 106
 
107
+  /**
108
+   * Dynamically add subpalettes on runtime
109
+   *
110
+   * @param DataContainer $dc
111
+   */
100 112
   public function registerSubPalettes(\DataContainer $dc)
101 113
   {
102 114
     $Layouts = \Database::getInstance()->execute("SELECT * FROM tl_article_layouts");
Browse code

Show the class name in articles layout selection

Benjamin Roth authored on13/07/2016 09:33:54
Showing1 changed files
... ...
@@ -91,7 +91,7 @@ class tl_article_eSM_artLayout extends Backend
91 91
 
92 92
     while ($ArticleLayouts->next())
93 93
     {
94
-      $arrArticleLayouts[$ArticleLayouts->name][$ArticleLayouts->id] = $ArticleLayouts->title;
94
+      $arrArticleLayouts[$ArticleLayouts->name][$ArticleLayouts->id] = $ArticleLayouts->title." [".$ArticleLayouts->alias."]";
95 95
     }
96 96
 
97 97
     return $arrArticleLayouts;
Browse code

Allow the use of article layouts from any theme

Benjamin Roth authored on13/07/2016 09:32:53
Showing1 changed files
... ...
@@ -33,7 +33,7 @@ $GLOBALS['TL_DCA']['tl_article']['fields']['es_type'] = array
33 33
   'exclude'                 => true,
34 34
   'inputType'               => 'select',
35 35
   'options_callback'        => array('tl_article_eSM_artLayout','getArticleLayouts'),
36
-  'eval'                    => array('tl_class'=>'w50', 'includeBlankOption'=>true, 'submitOnChange'=>true),
36
+  'eval'                    => array('chosen'=>true, 'tl_class'=>'w50', 'includeBlankOption'=>true, 'submitOnChange'=>true),
37 37
   'sql'                     => "int(10) unsigned NOT NULL default '0'"
38 38
 );
39 39
 
... ...
@@ -86,29 +86,12 @@ class tl_article_eSM_artLayout extends Backend
86 86
   public function getArticleLayouts(\DataContainer $dc)
87 87
   {
88 88
 
89
-    $arrLayoutIds = array();
90
-    $PageModel = \PageModel::findWithDetails($dc->activeRecord->pid);
91
-    if ($PageModel->layout)
92
-    {
93
-      $arrLayoutIds[] = $PageModel->layout;
94
-    }
95
-    if ($PageModel->mobileLayout)
96
-    {
97
-      $arrLayoutIds[] = $PageModel->mobileLayout;
98
-    }
99
-
100
-    $Themes = \ThemeModel::findMultipleByIds($arrLayoutIds);
101
-    if ($Themes === null)
102
-    {
103
-      return array();
104
-    }
105
-
106 89
     $arrArticleLayouts = array();
107
-    $ArticleLayouts = \Database::getInstance()->execute("SELECT id, title FROM tl_article_layouts WHERE ".\Database::getInstance()->findInSet('pid',$Themes->fetchEach('id'))." ORDER BY sorting");
90
+    $ArticleLayouts = \Database::getInstance()->execute("SELECT al.id, al.title, al.alias, t.name FROM tl_article_layouts al, tl_theme t WHERE t.id = al.pid ORDER BY t.name, al.sorting");
108 91
 
109 92
     while ($ArticleLayouts->next())
110 93
     {
111
-      $arrArticleLayouts[$ArticleLayouts->id] = $ArticleLayouts->title;
94
+      $arrArticleLayouts[$ArticleLayouts->name][$ArticleLayouts->id] = $ArticleLayouts->title;
112 95
     }
113 96
 
114 97
     return $arrArticleLayouts;
Browse code

Initial commit

Benjamin Roth authored on13/07/2016 09:17:47
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,130 @@
1
+<?php
2
+
3
+/**
4
+ * ArtLayout for Contao
5
+ *
6
+ * Copyright (c) 2016 Benjamin Roth
7
+ *
8
+ * @link    http://www.esales-media.de
9
+ * @license commercial
10
+ */
11
+
12
+/**
13
+ * Callback
14
+ */
15
+
16
+$GLOBALS['TL_DCA']['tl_article']['config']['onload_callback'][] = array('tl_article_eSM_artLayout','registerSubPalettes');
17
+
18
+/**
19
+ * Extend default palette
20
+ */
21
+$GLOBALS['TL_DCA']['tl_article']['palettes']['__selector__'][] = 'es_type';
22
+$GLOBALS['TL_DCA']['tl_article']['palettes']['default'] = str_replace('customTpl;', 'customTpl,es_type;', $GLOBALS['TL_DCA']['tl_article']['palettes']['default']);
23
+
24
+
25
+/**
26
+ * Add fields to tl_article
27
+ */
28
+$GLOBALS['TL_DCA']['tl_article']['fields']['guests']['eval']['tl_class'] .= ' m12';
29
+
30
+$GLOBALS['TL_DCA']['tl_article']['fields']['es_type'] = array
31
+(
32
+  'label'                   => &$GLOBALS['TL_LANG']['tl_article']['es_type'],
33
+  'exclude'                 => true,
34
+  'inputType'               => 'select',
35
+  'options_callback'        => array('tl_article_eSM_artLayout','getArticleLayouts'),
36
+  'eval'                    => array('tl_class'=>'w50', 'includeBlankOption'=>true, 'submitOnChange'=>true),
37
+  'sql'                     => "int(10) unsigned NOT NULL default '0'"
38
+);
39
+
40
+$GLOBALS['TL_DCA']['tl_article']['fields']['es_maxWidth'] = array
41
+(
42
+  'label'                   => &$GLOBALS['TL_LANG']['tl_article']['es_maxWidth'],
43
+  'exclude'                 => true,
44
+  'inputType'               => 'checkbox',
45
+  'eval'                    => array('tl_class'=>'w50 m12'),
46
+  'sql'                     => "char(1) NOT NULL default '1'"
47
+);
48
+
49
+$GLOBALS['TL_DCA']['tl_article']['fields']['es_backgroundSRC'] = array
50
+(
51
+  'label'                   => &$GLOBALS['TL_LANG']['tl_article']['es_backgroundSRC'],
52
+  'exclude'                 => true,
53
+  'inputType'               => 'fileTree',
54
+  'eval'                    => array('filesOnly'=>true, 'fieldType'=>'radio', 'mandatory'=>true, 'tl_class'=>'clr', 'extensions' => \Config::get('validImageTypes')),
55
+  'sql'                     => "binary(16) NULL"
56
+);
57
+
58
+$GLOBALS['TL_DCA']['tl_article']['fields']['es_size'] = array
59
+(
60
+  'label'                   => &$GLOBALS['TL_LANG']['tl_article']['es_size'],
61
+  'exclude'                 => true,
62
+  'inputType'               => 'imageSize',
63
+  'options'                 => System::getImageSizes(),
64
+  'reference'               => &$GLOBALS['TL_LANG']['MSC'],
65
+  'eval'                    => array('rgxp'=>'natural', 'includeBlankOption'=>true, 'nospace'=>true, 'helpwizard'=>true, 'tl_class'=>'w50'),
66
+  'sql'                     => "varchar(64) NOT NULL default ''"
67
+);
68
+
69
+/**
70
+ * Provide miscellaneous methods that are used by the data configuration array.
71
+ *
72
+ * @author Benjamin Roth <http://www.esales-media.de>
73
+ */
74
+class tl_article_eSM_artLayout extends Backend
75
+{
76
+
77
+  /**
78
+   * Import the back end user object
79
+   */
80
+  public function __construct()
81
+  {
82
+    parent::__construct();
83
+    $this->import('BackendUser', 'User');
84
+  }
85
+
86
+  public function getArticleLayouts(\DataContainer $dc)
87
+  {
88
+
89
+    $arrLayoutIds = array();
90
+    $PageModel = \PageModel::findWithDetails($dc->activeRecord->pid);
91
+    if ($PageModel->layout)
92
+    {
93
+      $arrLayoutIds[] = $PageModel->layout;
94
+    }
95
+    if ($PageModel->mobileLayout)
96
+    {
97
+      $arrLayoutIds[] = $PageModel->mobileLayout;
98
+    }
99
+
100
+    $Themes = \ThemeModel::findMultipleByIds($arrLayoutIds);
101
+    if ($Themes === null)
102
+    {
103
+      return array();
104
+    }
105
+
106
+    $arrArticleLayouts = array();
107
+    $ArticleLayouts = \Database::getInstance()->execute("SELECT id, title FROM tl_article_layouts WHERE ".\Database::getInstance()->findInSet('pid',$Themes->fetchEach('id'))." ORDER BY sorting");
108
+
109
+    while ($ArticleLayouts->next())
110
+    {
111
+      $arrArticleLayouts[$ArticleLayouts->id] = $ArticleLayouts->title;
112
+    }
113
+
114
+    return $arrArticleLayouts;
115
+  }
116
+
117
+  public function registerSubPalettes(\DataContainer $dc)
118
+  {
119
+    $Layouts = \Database::getInstance()->execute("SELECT * FROM tl_article_layouts");
120
+
121
+    while ($Layouts->next())
122
+    {
123
+      if ($Layouts->showBackgroundImage)
124
+      {
125
+        $GLOBALS['TL_DCA']['tl_article']['subpalettes']['es_type_'.$Layouts->id] = 'es_backgroundSRC';
126
+      }
127
+    }
128
+
129
+  }
130
+}