Skip to content

Commit

Permalink
Merge branch '5.2-dev' into 5.3-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Oct 14, 2024
2 parents b400100 + dde18c3 commit 1663f79
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
24 changes: 11 additions & 13 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 Expand Up @@ -181,7 +179,7 @@
type="radio"
label="MOD_ARTICLES_FIELD_TITLEONLY_LABEL"
layout="joomla.form.field.radio.switcher"
default="1"
default="0"
filter="integer"
>
<option value="0">JNO</option>
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
2 changes: 1 addition & 1 deletion modules/mod_articles/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}
}

$layoutSuffix = $params->get('title_only', 1) ? '_titles' : '_items';
$layoutSuffix = $params->get('title_only', 0) ? '_titles' : '_items';

?>
<?php if ($grouped) : ?>
Expand Down

0 comments on commit 1663f79

Please sign in to comment.