Skip to content

Commit

Permalink
[5.2RC3] fix to exclude current article even in include mode (#44213)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeutz authored Oct 11, 2024
1 parent 9e4dacf commit de2f060
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
22 changes: 10 additions & 12 deletions modules/mod_articles/mod_articles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,28 @@
showon="show_child_category_articles:1"
/>

<field
name="ex_or_include_articles"
type="list"
label="MOD_ARTICLES_FIELD_EX_OR_INCLUDE_LABEL"
default="0"
filter="integer"
>
<option value="0">MOD_ARTICLES_OPTION_EXCLUDE_VALUE</option>
<option value="1">MOD_ARTICLES_OPTION_INCLUDE_VALUE</option>
</field>

<field
name="exclude_current"
type="radio"
label="MOD_ARTICLES_FIELD_EXCLUDE_CURRENT_LABEL"
layout="joomla.form.field.radio.switcher"
default="1"
filter="integer"
showon="ex_or_include_articles:0"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

<field
name="ex_or_include_articles"
type="list"
label="MOD_ARTICLES_FIELD_EX_OR_INCLUDE_LABEL"
default="0"
filter="integer"
>
<option value="0">MOD_ARTICLES_OPTION_EXCLUDE_VALUE</option>
<option value="1">MOD_ARTICLES_OPTION_INCLUDE_VALUE</option>
</field>

<field
name="excluded_articles"
Expand Down
32 changes: 26 additions & 6 deletions modules/mod_articles/src/Helper/ArticlesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,27 +216,47 @@ public function getArticles(Registry $params, SiteApplication $app)
$ex_or_include_articles = $params->get('ex_or_include_articles', 0);
$filterInclude = true;
$articlesList = [];
$currentArticleId = $input->get('id', 0, 'UINT');

$isArticleAndShouldExcluded = $params->get('exclude_current', 1) === 1
&& $input->get('option') === 'com_content'
&& $input->get('view') === 'article';

$articlesListToProcess = $params->get('included_articles', '');

if ($ex_or_include_articles === 0) {
$filterInclude = false;

if (
$params->get('exclude_current', 1) === 1
&& $input->get('option') === 'com_content'
&& $input->get('view') === 'article'
) {
$articlesList[] = $input->get('id', 0, 'UINT');
if ($isArticleAndShouldExcluded) {
$articlesList[] = $currentArticleId;
}

$articlesListToProcess = $params->get('excluded_articles', '');
}

foreach (ArrayHelper::fromObject($articlesListToProcess) as $article) {
if (
$ex_or_include_articles === 1
&& $isArticleAndShouldExcluded
&& (int) $article['id'] === $currentArticleId
) {
continue;
}

$articlesList[] = (int) $article['id'];
}

// Edge case when the user select include mode but didn't add an article,
// we might have to exclude the current article
if (
$ex_or_include_articles === 1
&& $isArticleAndShouldExcluded
&& empty($articlesList)
) {
$filterInclude = false;
$articlesList[] = $currentArticleId;
}

if (!empty($articlesList)) {
$articles->setState('filter.article_id', $articlesList);
$articles->setState('filter.article_id.include', $filterInclude);
Expand Down

0 comments on commit de2f060

Please sign in to comment.