| ... | ... |
@@ -20,7 +20,7 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['type']['options_callback'] = array('
|
| 20 | 20 |
* |
| 21 | 21 |
* @author Benjamin Roth <http://www.esales-media.de> |
| 22 | 22 |
*/ |
| 23 |
-class tl_content_eSM_artLayout extends Backend |
|
| 23 |
+class tl_content_eSM_artLayout extends \Backend |
|
| 24 | 24 |
{
|
| 25 | 25 |
|
| 26 | 26 |
/** |
| ... | ... |
@@ -32,25 +32,39 @@ class tl_content_eSM_artLayout extends Backend |
| 32 | 32 |
$this->import('BackendUser', 'User');
|
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 |
- public function getContentElements(DataContainer $dc) |
|
| 35 |
+ /** |
|
| 36 |
+ * Return all allowed content elements |
|
| 37 |
+ * |
|
| 38 |
+ * @param DataContainer $dc |
|
| 39 |
+ * |
|
| 40 |
+ * @return array |
|
| 41 |
+ */ |
|
| 42 |
+ public function getContentElements(\DataContainer $dc) |
|
| 36 | 43 |
{
|
| 37 | 44 |
$groups = array(); |
| 38 | 45 |
|
| 46 |
+ // Get article model |
|
| 39 | 47 |
$Article = \ArticleModel::findByPk($dc->activeRecord->pid); |
| 40 |
- |
|
| 48 |
+ |
|
| 49 |
+ // Check for article layout |
|
| 41 | 50 |
if ($Article->es_type) |
| 42 | 51 |
{
|
| 52 |
+ // Get layout model |
|
| 43 | 53 |
$ArticleLayout = \ArticleLayoutsModel::findByPk($Article->es_type); |
| 44 | 54 |
|
| 55 |
+ // Build array of allowed elements if restriction is set |
|
| 45 | 56 |
if ($ArticleLayout !== null && $ArticleLayout->restrictContentElements) |
| 46 | 57 |
{
|
| 47 | 58 |
$arrAllowedCTE = deserialize($ArticleLayout->allowedElements,true); |
| 48 | 59 |
} |
| 49 | 60 |
} |
| 50 | 61 |
|
| 62 |
+ // Build elements groups |
|
| 51 | 63 |
foreach ($GLOBALS['TL_CTE'] as $k => $v) |
| 52 | 64 |
{
|
| 53 | 65 |
foreach (array_keys($v) as $kk) {
|
| 66 |
+ |
|
| 67 |
+ // Skip not allowed elements |
|
| 54 | 68 |
if (isset($arrAllowedCTE)) |
| 55 | 69 |
{
|
| 56 | 70 |
if (!in_array($kk, $arrAllowedCTE)) |
| 1 | 1 |
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 |