|
10 | 10 |
|
11 | 11 | namespace Joomla\Component\Weblinks\Site\View\Weblink; |
12 | 12 |
|
| 13 | +use Joomla\CMS\Event\Content; |
13 | 14 | use Joomla\CMS\Factory; |
14 | 15 | use Joomla\CMS\MVC\View\GenericDataException; |
15 | 16 | use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; |
@@ -75,23 +76,45 @@ public function display($tpl = null) |
75 | 76 | $this->handleModelErrors($errors); |
76 | 77 | } |
77 | 78 |
|
78 | | - PluginHelper::importPlugin('content'); |
79 | | - |
80 | 79 | // Create a shortcut for $item. |
81 | 80 | $item = $this->item; |
82 | 81 | $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id; |
83 | 82 | $temp = $item->params; |
84 | 83 | $item->params = clone $app->getParams(); |
85 | 84 | $item->params->merge($temp); |
86 | 85 | $offset = $this->state->get('list.offset'); |
87 | | - $app->triggerEvent('onContentPrepare', ['com_weblinks.weblink', &$item, &$item->params, $offset]); |
88 | | - $item->event = new \stdClass(); |
89 | | - $results = $app->triggerEvent('onContentAfterTitle', ['com_weblinks.weblink', &$item, &$item->params, $offset]); |
90 | | - $item->event->afterDisplayTitle = trim(implode("\n", $results)); |
91 | | - $results = $app->triggerEvent('onContentBeforeDisplay', ['com_weblinks.weblink', &$item, &$item->params, $offset]); |
92 | | - $item->event->beforeDisplayContent = trim(implode("\n", $results)); |
93 | | - $results = $app->triggerEvent('onContentAfterDisplay', ['com_weblinks.weblink', &$item, &$item->params, $offset]); |
94 | | - $item->event->afterDisplayContent = trim(implode("\n", $results)); |
| 86 | + |
| 87 | + $dispatcher = $this->getDispatcher(); |
| 88 | + |
| 89 | + // Process the content plugins. |
| 90 | + PluginHelper::importPlugin('content', null, true, $dispatcher); |
| 91 | + |
| 92 | + $contentEventArguments = [ |
| 93 | + 'context' => 'com_weblinks.weblink', |
| 94 | + 'subject' => $item, |
| 95 | + 'params' => $item->params, |
| 96 | + 'page' => $offset, |
| 97 | + ]; |
| 98 | + |
| 99 | + $dispatcher->dispatch( |
| 100 | + 'onContentPrepare', |
| 101 | + new Content\ContentPrepareEvent('onContentPrepare', $contentEventArguments) |
| 102 | + ); |
| 103 | + |
| 104 | + // Extra content from events |
| 105 | + $item->event = new \stdClass(); |
| 106 | + $contentEvents = [ |
| 107 | + 'afterDisplayTitle' => new Content\AfterTitleEvent('onContentAfterTitle', $contentEventArguments), |
| 108 | + 'beforeDisplayContent' => new Content\BeforeDisplayEvent('onContentBeforeDisplay', $contentEventArguments), |
| 109 | + 'afterDisplayContent' => new Content\AfterDisplayEvent('onContentAfterDisplay', $contentEventArguments), |
| 110 | + ]; |
| 111 | + |
| 112 | + foreach ($contentEvents as $resultKey => $event) { |
| 113 | + $results = $dispatcher->dispatch($event->getName(), $event)->getArgument('result', []); |
| 114 | + |
| 115 | + $item->event->{$resultKey} = $results ? trim(implode("\n", $results)) : ''; |
| 116 | + } |
| 117 | + |
95 | 118 | parent::display($tpl); |
96 | 119 | } |
97 | 120 |
|
|
0 commit comments