Browse code

Allow restricting the available content elements for articles using article layouts

Benjamin Roth authored on13/07/2016 10:18:11
Showing5 changed files
... ...
@@ -99,14 +99,15 @@ $GLOBALS['TL_DCA']['tl_article_layouts'] = array
99 99
 	// Palettes
100 100
 	'palettes' => array
101 101
 	(
102
-		'__selector__'              => array('showBackgroundImage'),
103
-		'default'                   => '{title_legend},title,alias;{content_legend},maxWidth,center,useHelper;{image_legend},showBackgroundImage'
102
+		'__selector__'              => array('showBackgroundImage','restrictContentElements'),
103
+		'default'                   => '{title_legend},title,alias;{content_legend},maxWidth,center,useHelper;{image_legend},showBackgroundImage;{expert_legend:hide},restrictContentElements'
104 104
 	),
105 105
 
106 106
 	// Subpalettes
107 107
 	'subpalettes' => array
108 108
 	(
109
-		'showBackgroundImage'       => 'bgImageSize,bgStyle'
109
+		'showBackgroundImage'       => 'bgImageSize,bgStyle',
110
+		'restrictContentElements'   => 'allowedElements'
110 111
 	),
111 112
 
112 113
 	// Fields
... ...
@@ -202,6 +203,24 @@ $GLOBALS['TL_DCA']['tl_article_layouts'] = array
202 203
 			'eval'                    => array('tl_class'=>'long','maxlength'=>255),
203 204
 			'sql'                     => "varchar(255) NOT NULL default ''"
204 205
 		),
206
+		'restrictContentElements' => array
207
+		(
208
+			'label'                   => &$GLOBALS['TL_LANG']['tl_article_layouts']['restrictContentElements'],
209
+			'exclude'                 => true,
210
+			'inputType'               => 'checkbox',
211
+			'eval'                    => array('submitOnChange'=>true),
212
+			'sql'                     => "char(1) NOT NULL default ''"
213
+		),
214
+		'allowedElements' => array
215
+		(
216
+			'label'                   => &$GLOBALS['TL_LANG']['tl_article_layouts']['allowedElements'],
217
+			'exclude'                 => true,
218
+			'inputType'               => 'checkbox',
219
+			'options_callback'        => array('tl_article_layouts','getContentElements'),
220
+			'reference'               => &$GLOBALS['TL_LANG']['CTE'],
221
+			'eval'                    => array('multiple'=>true,'mandatory'=>true),
222
+			'sql'                     => "blob NULL"
223
+		),
205 224
 	)
206 225
 );
207 226
 
... ...
@@ -292,4 +311,24 @@ class tl_article_layouts extends Backend
292 311
 		return '<div style="float:left">'. $row['title'] .' <span style="color:#b3b3b3;">['.$row['alias']."]</span></div>\n";
293 312
 	}
294 313
 
314
+	/**
315
+	 * Return all content elements as array
316
+	 *
317
+	 * @return array
318
+	 */
319
+	public function getContentElements()
320
+	{
321
+		$groups = array();
322
+
323
+		foreach ($GLOBALS['TL_CTE'] as $k=>$v)
324
+		{
325
+			foreach (array_keys($v) as $kk)
326
+			{
327
+				$groups[$k][] = $kk;
328
+			}
329
+		}
330
+
331
+		return $groups;
332
+	}
333
+
295 334
 }
296 335
new file mode 100644
... ...
@@ -0,0 +1,67 @@
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
+ * Callbacks
14
+ */
15
+$GLOBALS['TL_DCA']['tl_content']['fields']['type']['options_callback'] = array('tl_content_eSM_artLayout','getContentElements');
16
+
17
+
18
+/**
19
+ * Provide miscellaneous methods that are used by the data configuration array.
20
+ *
21
+ * @author Benjamin Roth <http://www.esales-media.de>
22
+ */
23
+class tl_content_eSM_artLayout extends Backend
24
+{
25
+
26
+  /**
27
+   * Import the back end user object
28
+   */
29
+  public function __construct()
30
+  {
31
+    parent::__construct();
32
+    $this->import('BackendUser', 'User');
33
+  }
34
+
35
+  public function getContentElements(DataContainer $dc)
36
+  {
37
+    $groups = array();
38
+
39
+    $Article = \ArticleModel::findByPk($dc->activeRecord->pid);
40
+    
41
+    if ($Article->es_type)
42
+    {
43
+      $ArticleLayout = \ArticleLayoutsModel::findByPk($Article->es_type);
44
+
45
+      if ($ArticleLayout !== null && $ArticleLayout->restrictContentElements)
46
+      {
47
+        $arrAllowedCTE = deserialize($ArticleLayout->allowedElements,true);
48
+      }
49
+    }
50
+
51
+    foreach ($GLOBALS['TL_CTE'] as $k => $v)
52
+    {
53
+      foreach (array_keys($v) as $kk) {
54
+        if (isset($arrAllowedCTE))
55
+        {
56
+          if (!in_array($kk, $arrAllowedCTE))
57
+          {
58
+            continue;
59
+          }
60
+        }
61
+        $groups[$k][] = $kk;
62
+      }
63
+    }
64
+
65
+    return $groups;
66
+  }
67
+}
0 68
\ No newline at end of file
... ...
@@ -28,6 +28,10 @@ $GLOBALS['TL_LANG']['tl_article_layouts']['bgStyle'][0] = 'Eigener Inline-CSS Co
28 28
 $GLOBALS['TL_LANG']['tl_article_layouts']['bgStyle'][1] = 'Hier können Sie einen eigenen Inline-CSS Code für das Hintergrundbild angeben. ##bg_image## wird ersetzt durch den Bildpfad.';
29 29
 $GLOBALS['TL_LANG']['tl_article_layouts']['useHelper'][0] = 'Zusätzlicher Content-Wrapper';
30 30
 $GLOBALS['TL_LANG']['tl_article_layouts']['useHelper'][1] = 'Fügt einen zusätzlichen Content-Wrapper innerhalb des inside Containers hinzu.';
31
+$GLOBALS['TL_LANG']['tl_article_layouts']['restrictContentElements'][0] = 'Artikel Content-Elemente einschränken';
32
+$GLOBALS['TL_LANG']['tl_article_layouts']['restrictContentElements'][1] = 'Erlaubt es, die im Artikel zur Verfügung stehenden Content-Elemente einzuschränken.';
33
+$GLOBALS['TL_LANG']['tl_article_layouts']['allowedElements'][0] = 'Erlaubte Content Elemente';
34
+$GLOBALS['TL_LANG']['tl_article_layouts']['allowedElements'][1] = 'Nur die ausgewählten Content-Elemente stehen im Artikel zur Verfügung.';
31 35
 
32 36
 /**
33 37
  * Legends
... ...
@@ -35,3 +39,4 @@ $GLOBALS['TL_LANG']['tl_article_layouts']['useHelper'][1] = 'Fügt einen zusätz
35 39
 $GLOBALS['TL_LANG']['tl_article_layouts']['title_legend'] = 'Titel/Klassenname';
36 40
 $GLOBALS['TL_LANG']['tl_article_layouts']['content_legend'] = 'Inhalt-Einstellungen';
37 41
 $GLOBALS['TL_LANG']['tl_article_layouts']['image_legend'] = 'Bild-Einstellungen';
42
+$GLOBALS['TL_LANG']['tl_article_layouts']['expert_legend'] = 'Experten-Einstellungen';
... ...
@@ -28,6 +28,10 @@ $GLOBALS['TL_LANG']['tl_article_layouts']['bgStyle'][0] = 'Custom inline CSS cod
28 28
 $GLOBALS['TL_LANG']['tl_article_layouts']['bgStyle'][1] = 'Here you can define a custom inline CSS code to be used for the background image. ##bg_image## will be replaced with the image path.';
29 29
 $GLOBALS['TL_LANG']['tl_article_layouts']['useHelper'][0] = 'Additional content wrapper';
30 30
 $GLOBALS['TL_LANG']['tl_article_layouts']['useHelper'][1] = 'Inserts an additional content wrapper within the inside container.';
31
+$GLOBALS['TL_LANG']['tl_article_layouts']['restrictContentElements'][0] = 'Restrict article content elements';
32
+$GLOBALS['TL_LANG']['tl_article_layouts']['restrictContentElements'][1] = 'Allows to restrict the available content elements in the article.';
33
+$GLOBALS['TL_LANG']['tl_article_layouts']['allowedElements'][0] = 'Allowed content elements';
34
+$GLOBALS['TL_LANG']['tl_article_layouts']['allowedElements'][1] = 'Only selected content elements are available in the article.';
31 35
 
32 36
 /**
33 37
  * Legends
... ...
@@ -35,3 +39,4 @@ $GLOBALS['TL_LANG']['tl_article_layouts']['useHelper'][1] = 'Inserts an addition
35 39
 $GLOBALS['TL_LANG']['tl_article_layouts']['title_legend'] = 'Title';
36 40
 $GLOBALS['TL_LANG']['tl_article_layouts']['content_legend'] = 'Content settings';
37 41
 $GLOBALS['TL_LANG']['tl_article_layouts']['image_legend'] = 'Image settings';
42
+$GLOBALS['TL_LANG']['tl_article_layouts']['expert_legend'] = 'Expert settings';
... ...
@@ -27,6 +27,8 @@ namespace eSM_artLayout;
27 27
  * @property integer $maxWidth
28 28
  * @property integer $useHelper
29 29
  * @property string  $bgStyle
30
+ * @property integer $restrictContentElements
31
+ * @property string  $allowedElements
30 32
  *
31 33
  * @method static \ThemeModel|null findById($id, $opt=array())
32 34
  * @method static \ThemeModel|null findByPk($id, $opt=array())