joomlagerman / joomla

The J!German translation team provides German translation for Joomla!
https://www.jgerman.de
GNU General Public License v2.0
25 stars 46 forks source link

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

Closed jgerman-bot closed 1 month ago

jgerman-bot commented 1 month ago

New language relevant PR in upstream repo: https://github.com/joomla/joomla-cms/pull/44145 Here are the upstream changes:

Click to expand the diff! ```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="Normal Mode displays a static list of Articles.
Dynamic Mode 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 @@
+ + + + + + + + + + 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], ```