Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.2] Articles Module: (Re)Introduced dynamic mode as on mod_articles_category #3298

Closed
jgerman-bot opened this issue Sep 29, 2024 · 0 comments · Fixed by #3303
Closed

[5.2] Articles Module: (Re)Introduced dynamic mode as on mod_articles_category #3298

jgerman-bot opened this issue Sep 29, 2024 · 0 comments · Fixed by #3303

Comments

@jgerman-bot
Copy link

New language relevant PR in upstream repo: joomla/joomla-cms#44145 Here are the upstream changes:

Click to expand the diff!
diff --git a/language/en-GB/mod_articles.ini b/language/en-GB/mod_articles.ini
index d7a2d7d0485d..819e65b5e714 100644
--- a/language/en-GB/mod_articles.ini
+++ b/language/en-GB/mod_articles.ini
@@ -48,6 +48,8 @@ MOD_ARTICLES_FIELD_LAYOUT_MULTILINE="Multiline"
 MOD_ARTICLES_FIELD_LAYOUT_SINGLELINE="Single Line"
 MOD_ARTICLES_FIELD_LAYOUT_VERT="Vertical"
 MOD_ARTICLES_FIELD_LINKTITLES_LABEL="Title Link"
+MOD_ARTICLES_FIELD_MODE_DESC="<em><strong>Normal Mode</strong></em> displays a static list of Articles.<br><em><strong>Dynamic Mode</strong></em> dynamically detects if on a Category view and displays the list of articles within that Category. It is best to display on all pages as it will decide to display anything dynamically."
+MOD_ARTICLES_FIELD_MODE_LABEL="Mode"
 MOD_ARTICLES_FIELD_MONTHYEARFORMAT_DESC="Please enter in a valid date format. See: https://php.net/date for formatting information."
 MOD_ARTICLES_FIELD_MONTHYEARFORMAT_LABEL="Month and Year Display Format"
 MOD_ARTICLES_FIELD_ONLYARCHIVED_LABEL="Archived Articles"
@@ -59,6 +61,8 @@ MOD_ARTICLES_FIELD_SHOWCHILDCATEGORYARTICLES_LABEL="Child Category Articles"
 MOD_ARTICLES_FIELD_SHOWFEATURED_LABEL="Featured Articles"
 MOD_ARTICLES_FIELD_SHOWHITS_LABEL="Hits"
 MOD_ARTICLES_FIELD_SHOWINTROTEXT_LABEL="Introtext"
+MOD_ARTICLES_FIELD_SHOWONARTICLEPAGE_DESC="Select to Show or hide Article List from Article Pages. This means that the module will only display itself dynamically on Category Pages."
+MOD_ARTICLES_FIELD_SHOWONARTICLEPAGE_LABEL="Show on Article Page"
 MOD_ARTICLES_FIELD_STARTDATE_LABEL="Start Date Range"
 MOD_ARTICLES_FIELD_TITLEONLY_LABEL="Title Only (lists)"
 MOD_ARTICLES_FIELD_TITLE_HEADING="Header Level"
@@ -71,6 +75,7 @@ MOD_ARTICLES_OPTION_ASCENDING_VALUE="Ascending"
 MOD_ARTICLES_OPTION_CREATED_VALUE="Created Date"
 MOD_ARTICLES_OPTION_DATERANGE_VALUE="Date Range"
 MOD_ARTICLES_OPTION_DESCENDING_VALUE="Descending"
+MOD_ARTICLES_OPTION_DYNAMIC_VALUE="Dynamic"
 MOD_ARTICLES_OPTION_EXCLUDE_VALUE="Exclude"
 MOD_ARTICLES_OPTION_EXCLUSIVE_VALUE="Exclusive"
 MOD_ARTICLES_OPTION_FINISHPUBLISHING_VALUE="Finish Publishing Date"
diff --git a/modules/mod_articles/mod_articles.xml b/modules/mod_articles/mod_articles.xml
index bd0d2ad7fda0..cbffe0f39c43 100644
--- a/modules/mod_articles/mod_articles.xml
+++ b/modules/mod_articles/mod_articles.xml
@@ -24,6 +24,32 @@
 		<fields name="params">
 			<fieldset name="basic"
 					addfieldprefix="Joomla\Component\Content\Administrator\Field" >
+				<field
+					name="mode"
+					type="list"
+					label="MOD_ARTICLES_FIELD_MODE_LABEL"
+					description="MOD_ARTICLES_FIELD_MODE_DESC"
+					default="normal"
+					validate="options"
+					>
+					<option value="normal">MOD_ARTICLES_OPTION_NORMAL_VALUE</option>
+					<option value="dynamic">MOD_ARTICLES_OPTION_DYNAMIC_VALUE</option>
+				</field>
+
+				<field
+					name="show_on_article_page"
+					type="radio"
+					label="MOD_ARTICLES_FIELD_SHOWONARTICLEPAGE_LABEL"
+					description="MOD_ARTICLES_FIELD_SHOWONARTICLEPAGE_DESC"
+					layout="joomla.form.field.radio.switcher"
+					default="1"
+					filter="integer"
+					showon="mode:dynamic"
+					>
+					<option value="0">JNO</option>
+					<option value="1">JYES</option>
+				</field>
+
 				<field
 					name="count"
 					type="number"
diff --git a/modules/mod_articles/src/Dispatcher/Dispatcher.php b/modules/mod_articles/src/Dispatcher/Dispatcher.php
index f3c93d9c2528..1e48898b63f3 100644
--- a/modules/mod_articles/src/Dispatcher/Dispatcher.php
+++ b/modules/mod_articles/src/Dispatcher/Dispatcher.php
@@ -40,12 +40,40 @@ protected function getLayoutData(): array
         $data   = parent::getLayoutData();
         $params = $data['params'];
 
+        // Prep for Normal or Dynamic Modes
+        $mode   = $params->get('mode', 'normal');
+        $idBase = null;
+
+        switch ($mode) {
+            case 'dynamic':
+                $option = $data['input']->get('option');
+                $view   = $data['input']->get('view');
+
+                if ($option === 'com_content') {
+                    switch ($view) {
+                        case 'category':
+                        case 'categories':
+                            $idBase = $data['input']->getInt('id');
+                            break;
+                        case 'article':
+                            if ($params->get('show_on_article_page', 1)) {
+                                $idBase = $data['input']->getInt('catid');
+                            }
+                            break;
+                    }
+                }
+                break;
+            default:
+                $idBase = $params->get('catid');
+                break;
+        }
+
         $cacheParams               = new \stdClass();
         $cacheParams->cachemode    = 'id';
         $cacheParams->class        = $this->getHelperFactory()->getHelper('ArticlesHelper');
         $cacheParams->method       = 'getArticles';
         $cacheParams->methodparams = [$params, $data['app']];
-        $cacheParams->modeparams   = md5(serialize([$params->get('catid'), $this->module->module, $this->module->id]));
+        $cacheParams->modeparams   = md5(serialize([$idBase, $this->module->module, $this->module->id]));
 
         $data['list'] = ModuleHelper::moduleCache($this->module, $params, $cacheParams);
 
diff --git a/modules/mod_articles/src/Helper/ArticlesHelper.php b/modules/mod_articles/src/Helper/ArticlesHelper.php
index a8c2b9865c20..33b6d41be513 100644
--- a/modules/mod_articles/src/Helper/ArticlesHelper.php
+++ b/modules/mod_articles/src/Helper/ArticlesHelper.php
@@ -75,8 +75,59 @@ public function getArticles(Registry $params, SiteApplication $app)
         $authorised = Access::getAuthorisedViewLevels($app->getIdentity()->get('id'));
         $articles->setState('filter.access', $access);
 
-        $catids = $params->get('catid');
-        $articles->setState('filter.category_id.include', (bool) $params->get('category_filtering_type', 1));
+        // Prep for Normal or Dynamic Modes
+        $mode = $params->get('mode', 'normal');
+
+        switch ($mode) {
+            case 'dynamic':
+                $option = $input->get('option');
+                $view   = $input->get('view');
+
+                if ($option === 'com_content') {
+                    switch ($view) {
+                        case 'category':
+                        case 'categories':
+                            $catids = [$input->getInt('id')];
+                            break;
+                        case 'article':
+                            if ($params->get('show_on_article_page', 1)) {
+                                $article_id = $input->getInt('id');
+                                $catid      = $input->getInt('catid');
+
+                                if (!$catid) {
+                                    // Get an instance of the generic article model
+                                    $article = $factory->createModel('Article', 'Site', ['ignore_request' => true]);
+
+                                    $article->setState('params', $appParams);
+                                    $article->setState('filter.published', 1);
+                                    $article->setState('article.id', (int) $article_id);
+                                    $item   = $article->getItem();
+                                    $catids = [$item->catid];
+                                } else {
+                                    $catids = [$catid];
+                                }
+                            } else {
+                                // Return right away if show_on_article_page option is off
+                                return;
+                            }
+                            break;
+
+                        default:
+                            // Return right away if not on the category or article views
+                            return;
+                    }
+                } else {
+                    // Return right away if not on a com_content page
+                    return;
+                }
+
+                break;
+
+            default:
+                $catids = $params->get('catid');
+                $articles->setState('filter.category_id.include', (bool) $params->get('category_filtering_type', 1));
+                break;
+        }
 
         // Category filter
         if ($catids) {
diff --git a/plugins/sampledata/blog/src/Extension/Blog.php b/plugins/sampledata/blog/src/Extension/Blog.php
index 326c8f358084..f862b441ca2e 100644
--- a/plugins/sampledata/blog/src/Extension/Blog.php
+++ b/plugins/sampledata/blog/src/Extension/Blog.php
@@ -1432,6 +1432,8 @@ public function onAjaxSampledataApplyStep3()
                 'position' => 'sidebar-right',
                 'module'   => 'mod_articles',
                 'params'   => [
+                    'mode'                         => 'normal',
+                    'show_on_article_page'         => 1,
                     'count'                        => 10,
                     'category_filtering_type'      => 1,
                     'show_child_category_articles' => 0,
@@ -1498,6 +1500,8 @@ public function onAjaxSampledataApplyStep3()
                 'assignment' => 1,
                 'showtitle'  => 0,
                 'params'     => [
+                    'mode'                         => 'normal',
+                    'show_on_article_page'         => 1,
                     'count'                        => 3,
                     'category_filtering_type'      => 1,
                     'catid'                        => $catIds[2],
@@ -1560,6 +1564,8 @@ public function onAjaxSampledataApplyStep3()
                 'position' => 'bottom-b',
                 'module'   => 'mod_articles',
                 'params'   => [
+                    'mode'                         => 'normal',
+                    'show_on_article_page'         => 1,
                     'count'                        => 6,
                     'category_filtering_type'      => 1,
                     'catid'                        => $catIds[0],
@joomlagerman joomlagerman deleted a comment Sep 29, 2024
@tecpromotion tecpromotion changed the title Articles Module: (Re)Introduced dynamic mode as on mod_articles_category [5.2] Articles Module: (Re)Introduced dynamic mode as on mod_articles_category Sep 29, 2024
tecpromotion added a commit to tecpromotion/joomla that referenced this issue Sep 29, 2024
translation
@zero-24 zero-24 closed this as completed in acf1ed2 Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants