Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions language/en-GB/mod_articles.ini
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ MOD_ARTICLES_FIELD_TITLEONLY_LABEL="Title Only (lists)"
MOD_ARTICLES_FIELD_TITLE_HEADING="Header Level"
MOD_ARTICLES_FIELD_TITLE_HEADING_NONE="None"
MOD_ARTICLES_FIELD_TITLE_LABEL="Article Title"
MOD_ARTICLES_FIELD_TRIGGEREVENTS_DESC="Enable this option to trigger three plugin events (afterDisplayTitle, beforeDisplayContent, afterDisplayContent) for each article in the results list."
MOD_ARTICLES_FIELD_TRIGGEREVENTS_LABEL="Trigger Plugin Events"
MOD_ARTICLES_INFO="Details"
MOD_ARTICLES_OPTION_ASCENDING_VALUE="Ascending"
MOD_ARTICLES_OPTION_CREATED_VALUE="Created Date"
Expand Down
13 changes: 13 additions & 0 deletions modules/mod_articles/mod_articles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,19 @@
<option value="1">JSHOW</option>
</field>

<field
name="triggerevents"
type="radio"
label="MOD_ARTICLES_FIELD_TRIGGEREVENTS_LABEL"
description="MOD_ARTICLES_FIELD_TRIGGEREVENTS_DESC"
layout="joomla.form.field.radio.switcher"
default="0"
filter="integer"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

<field
name="show_introtext"
type="radio"
Expand Down
36 changes: 36 additions & 0 deletions modules/mod_articles/src/Helper/ArticlesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Event\Content;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\Helpers\StringHelper as SpecialStringHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Plugin\PluginHelper;
Expand Down Expand Up @@ -238,6 +240,40 @@ public function getArticles(Registry $params, SiteApplication $app)
$item->link = Route::_('index.php?option=com_users&view=login&Itemid=' . $Itemid . '&return=' . $return);
}

$item->event = new \stdClass();

// Check if we should trigger additional plugin events
if ($params->get('triggerevents', 0)) {
$dispatcher = Factory::getApplication()->getDispatcher();

// Process the content plugins.
PluginHelper::importPlugin('content', null, true, $dispatcher);

$contentEventArguments = [
'context' => 'com_content.article',
Comment thread
RickR2H marked this conversation as resolved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was merged with wrong context, what happened? 😄

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the mod_articles context will not load the custom fields. It needs to go through com_content or else information will be missing. I didn't feel like change plugin events.

'subject' => $item,
'params' => $item->params,
];

// Extra content from events

$contentEvents = [
'afterDisplayTitle' => new Content\AfterTitleEvent('onContentAfterTitle', $contentEventArguments),
'beforeDisplayContent' => new Content\BeforeDisplayEvent('onContentBeforeDisplay', $contentEventArguments),
'afterDisplayContent' => new Content\AfterDisplayEvent('onContentAfterDisplay', $contentEventArguments),
];

foreach ($contentEvents as $resultKey => $event) {
$results = $dispatcher->dispatch($event->getName(), $event)->getArgument('result', []);

$item->event->{$resultKey} = $results ? trim(implode("\n", $results)) : '';
}
} else {
$item->event->afterDisplayTitle = '';
$item->event->beforeDisplayContent = '';
$item->event->afterDisplayContent = '';
}

// Used for styling the active article
$item->active = $item->id == $active_article_id ? 'active' : '';

Expand Down
12 changes: 9 additions & 3 deletions modules/mod_articles/tmpl/default_items.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<ul class="mod-articles-items <?php echo ($params->get('articles_layout') == 1 ? 'mod-articles-grid ' . $gridCols : ''); ?> mod-list">
<?php foreach ($items as $item) : ?>
<?php
$displayInfo = $item->displayHits || $item->displayAuthorName || $item->displayCategoryTitle || $item->displayDate;
$displayInfo = $item->displayHits || $item->displayAuthorName || $item->displayCategoryTitle || $item->displayDate;
?>
<li>
<article class="mod-articles-item" itemscope itemtype="https://schema.org/Article">
Expand All @@ -44,6 +44,8 @@
</<?php echo $item_heading; ?>>
<?php endif; ?>

<?php echo $item->event->afterDisplayTitle; ?>

<?php if ($displayInfo) : ?>
<?php $listClass = ($params->get('info_layout') == 1) ? 'list-inline' : 'list-unstyled'; ?>
<dl class="<?php echo $listClass; ?>">
Expand Down Expand Up @@ -100,10 +102,14 @@
</div>
<?php endif; ?>

<?php if ($params->get('show_introtext')) : ?>
<?php echo $item->displayIntrotext; ?>
<?php echo $item->event->beforeDisplayContent; ?>

<?php if ($params->get('show_introtext', 1)) : ?>
<?php echo $item->introtext; ?>
<?php endif; ?>

<?php echo $item->event->afterDisplayContent; ?>

<?php if ($params->get('show_readmore')) : ?>
<?php echo LayoutHelper::render('joomla.content.readmore', ['item' => $item, 'params' => $item->params, 'link' => $item->link]); ?>
<?php endif; ?>
Expand Down