Browse code

Add possibility to hide article in article list module

Benjamin Roth authored on02/07/2019 15:00:41
Showing4 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,39 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of eSales Media ContentHelperBundle
5
+ *
6
+ * (c) Benjamin Roth
7
+ *
8
+ * @license proprietary
9
+ */
10
+
11
+namespace EsalesMedia\ContentHelperBundle\FrontendModule;
12
+
13
+use Contao\ArticleModel;
14
+
15
+/**
16
+ * Extends columns start content element
17
+ */
18
+class ArticleListModule extends \Contao\ModuleArticleList
19
+{
20
+
21
+    /**
22
+     * Generate the module
23
+     */
24
+    protected function compile()
25
+    {
26
+        parent::compile();
27
+
28
+        $articles = array();
29
+        foreach ($this->Template->articles as $article)
30
+        {
31
+            if (($Article = ArticleModel::findByPk($article['articleId'])) !== null && $Article->hideInArticleList)
32
+            {
33
+                continue;
34
+            }
35
+            $articles[] = $article;
36
+        }
37
+        $this->Template->articles = $articles;
38
+    }
39
+}
... ...
@@ -14,6 +14,11 @@
14 14
 $GLOBALS['TL_CTE']['rs_columns']['rs_columns_start'] = 'EsalesMedia\\ContentHelperBundle\\FrontendController\\ColumnsStart';
15 15
 $GLOBALS['TL_CTE']['rs_columns']['rs_column_start'] = 'EsalesMedia\\ContentHelperBundle\\FrontendController\\ColumnStart';
16 16
 
17
+/**
18
+ * Frontend module
19
+ */
20
+$GLOBALS['FE_MOD']['miscellaneous']['articlelist'] = 'EsalesMedia\\ContentHelperBundle\\FrontendModule\\ArticleListModule';
21
+
17 22
 
18 23
 /**
19 24
  * Hooks
20 25
new file mode 100644
... ...
@@ -0,0 +1,33 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of eSales Media ContentHelperBundle
5
+ *
6
+ * (c) Benjamin Roth
7
+ *
8
+ * @license proprietary
9
+ */
10
+
11
+/*
12
+ * Modify palettes
13
+ */
14
+foreach ($GLOBALS['TL_DCA']['tl_article']['palettes'] as $key => $palette)
15
+{
16
+    if ($key != '__selector__')
17
+    {
18
+        \Contao\CoreBundle\DataContainer\PaletteManipulator::create()->addField('hideInArticleList','teaser',\Contao\CoreBundle\DataContainer\PaletteManipulator::POSITION_AFTER)->applyToPalette($key,'tl_article');
19
+    }
20
+}
21
+
22
+/*
23
+ * Add fields
24
+ */
25
+
26
+$GLOBALS['TL_DCA']['tl_article']['fields']['hideInArticleList'] = array
27
+(
28
+    'label'                   => &$GLOBALS['TL_LANG']['tl_article']['hideInArticleList'],
29
+    'exclude'                 => true,
30
+    'inputType'               => 'checkbox',
31
+    'eval'                    => array('tl_class'=>'w50'),
32
+    'sql'                     => "char(1) NOT NULL default ''"
33
+);
0 34
new file mode 100644
... ...
@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+/*
4
+ * This file is part of eSales Media ContentHelperBundle
5
+ *
6
+ * (c) Benjamin Roth
7
+ *
8
+ * @license proprietary
9
+ */
10
+
11
+/**
12
+ * Fields
13
+ */
14
+$GLOBALS['TL_LANG']['tl_article']['hideInArticleList'][0] = 'In Artikelliste verstecken';
15
+$GLOBALS['TL_LANG']['tl_article']['hideInArticleList'][1] = 'Der Artikel wird in der Artikelliste nicht angezeigt';