escape($function) . '(document.getElementById("jform_title").value);
+ return window.parent.{$this->escape($function)}(document.getElementById("jform_title").value);
}
}
-');
+JS;
+$wa->addInlineScript($script);
?>
diff --git a/src/administrator/components/com_weblinks/tmpl/weblinks/default.php b/src/administrator/components/com_weblinks/tmpl/weblinks/default.php
index d8de17a640b..87ffd106893 100644
--- a/src/administrator/components/com_weblinks/tmpl/weblinks/default.php
+++ b/src/administrator/components/com_weblinks/tmpl/weblinks/default.php
@@ -24,11 +24,11 @@
HTMLHelper::_('behavior.multiselect');
$user = Factory::getApplication()->getIdentity();
$userId = $user->get('id');
-$listOrder = $this->escape($this->state->get('list.ordering'));
-$listDirn = $this->escape($this->state->get('list.direction'));
+$listOrder = $this->escape($this->getState()->get('list.ordering'));
+$listDirn = $this->escape($this->getState()->get('list.direction'));
$saveOrder = $listOrder == 'a.ordering';
$assoc = Associations::isEnabled();
-if ($saveOrder && !empty($this->items)) {
+if ($saveOrder && !empty($this->getItems())) {
$saveOrderingUrl = 'index.php?option=com_weblinks&task=weblinks.saveOrderAjax&tmpl=component';
HTMLHelper::_('draggablelist.draggable');
}
@@ -41,7 +41,7 @@
// Search tools bar
echo LayoutHelper::render('joomla.searchtools.default', ['view' => $this]);
?>
- items)) :
+ getItems())) :
?>
@@ -98,7 +98,7 @@
class="js-draggable" data-url="" data-direction="" data-nested="true">
- items as $i => $item) :
+ getItems() as $i => $item) :
?>
cat_link = Route::_('index.php?option=com_categories&extension=com_weblinks&task=edit&type=other&cid[]=' . $item->catid); ?>
authorise('core.create', 'com_weblinks.category.' . $item->catid); ?>
@@ -191,7 +191,7 @@
- pagination->getListFooter(); ?>
+ getPagination()->getListFooter(); ?>
getState('filter.access');
$options['published'] = $this->getState('filter.published');
$options['countItems'] = $params->get('show_cat_num_links', 1) || !$params->get('show_empty_categories_cat', 0);
- $categories = Categories::getInstance('Weblinks', $options);
+ $component = Factory::getApplication()->bootComponent('com_weblinks');
+ $categories = $component->getCategory($options);
$this->_parent = $categories->get($this->getState('filter.parentId', 'root'));
if (\is_object($this->_parent)) {
$this->_items = $this->_parent->getChildren();
diff --git a/src/components/com_weblinks/src/Model/CategoryModel.php b/src/components/com_weblinks/src/Model/CategoryModel.php
index fa6b4066484..3051fda7ed2 100644
--- a/src/components/com_weblinks/src/Model/CategoryModel.php
+++ b/src/components/com_weblinks/src/Model/CategoryModel.php
@@ -202,7 +202,7 @@ protected function getListQuery()
// Filter by language
if ($this->getState('filter.language')) {
- $query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
+ $query->whereIn($db->quoteName('a.language'), [Factory::getApplication()->getLanguage()->getTag(), '*'], ParameterType::STRING);
}
// Filter by search in title
@@ -308,7 +308,8 @@ public function getCategory()
$options['countItems'] = $params->get('show_cat_num_links_cat', 1)
|| $params->get('show_empty_categories', 0);
- $categories = Categories::getInstance('Weblinks', $options);
+ $component = Factory::getApplication()->bootComponent('com_weblinks');
+ $categories = $component->getCategory($options);
$this->_item = $categories->get($this->getState('category.id', 'root'));
if (\is_object($this->_item)) {
diff --git a/src/components/com_weblinks/src/Model/WeblinkModel.php b/src/components/com_weblinks/src/Model/WeblinkModel.php
index d8306c066a6..b208d5a0a85 100644
--- a/src/components/com_weblinks/src/Model/WeblinkModel.php
+++ b/src/components/com_weblinks/src/Model/WeblinkModel.php
@@ -113,7 +113,7 @@ public function getItem($pk = null)
// Filter by language
if ($this->getState('filter.language')) {
- $query->whereIn($db->quoteName('a.language'), [Factory::getLanguage()->getTag(), '*'], ParameterType::STRING);
+ $query->whereIn($db->quoteName('a.language'), [Factory::getApplication()->getLanguage()->getTag(), '*'], ParameterType::STRING);
}
// Join over the categories to get parent category titles
@@ -174,6 +174,7 @@ public function getItem($pk = null)
$this->_item[$pk] = $data;
} catch (\Exception $e) {
+ // @phpstan-ignore-next-line ItemModel::setError is designed to handle caught exceptions
$this->setError($e);
$this->_item[$pk] = false;
}
diff --git a/src/components/com_weblinks/src/Service/Router.php b/src/components/com_weblinks/src/Service/Router.php
index cf61ed422cf..61cac0ec016 100644
--- a/src/components/com_weblinks/src/Service/Router.php
+++ b/src/components/com_weblinks/src/Service/Router.php
@@ -72,7 +72,7 @@ class Router extends RouterView
* Weblinks Component router constructor
*
* @param SiteApplication $app The application object
- * @param AbstractMenu $menu The menu object to work with
+ * @param AbstractMenu $menu The menu object to work witha
* @param CategoryFactoryInterface $categoryFactory The category object
* @param DatabaseInterface $db The database object
*/
diff --git a/src/components/com_weblinks/src/View/Category/HtmlView.php b/src/components/com_weblinks/src/View/Category/HtmlView.php
index 75200e8ae1b..bcf528b8c20 100644
--- a/src/components/com_weblinks/src/View/Category/HtmlView.php
+++ b/src/components/com_weblinks/src/View/Category/HtmlView.php
@@ -10,6 +10,7 @@
namespace Joomla\Component\Weblinks\Site\View\Category;
+use Joomla\CMS\Factory;
use Joomla\CMS\MVC\View\CategoryView;
use Joomla\CMS\Router\Route;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
@@ -53,7 +54,7 @@ public function display($tpl = null)
}
}
- return parent::display($tpl);
+ parent::display($tpl);
}
/**
@@ -71,10 +72,12 @@ protected function prepareDocument()
}
// Get ID of the category from active menu item
- $menu = $this->menu;
+ $app = Factory::getApplication();
+ $menu = $app->getMenu()->getActive();
+ $pathway = $app->getPathway();
if (
- $menu && $menu->component == 'com_weblinks' && isset($menu->query['view'])
+ $menu && $menu->component === 'com_weblinks' && isset($menu->query['view'])
&& \in_array($menu->query['view'], ['categories', 'category'])
) {
$id = $menu->query['id'];
@@ -91,7 +94,7 @@ protected function prepareDocument()
$path = array_reverse($path);
foreach ($path as $item) {
- $this->pathway->addItem($item['title'], $item['link']);
+ $pathway->addItem($item['title'], $item['link']);
}
}
}
diff --git a/src/components/com_weblinks/src/View/Form/HtmlView.php b/src/components/com_weblinks/src/View/Form/HtmlView.php
index 368998021bd..96811a70330 100644
--- a/src/components/com_weblinks/src/View/Form/HtmlView.php
+++ b/src/components/com_weblinks/src/View/Form/HtmlView.php
@@ -16,8 +16,8 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
-use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
+use Joomla\CMS\User\User;
use Joomla\Component\Weblinks\Site\Model\FormModel;
/**
@@ -63,6 +63,12 @@ class HtmlView extends BaseHtmlView
*/
protected $params;
+ /**
+ * @var User
+ * @since __DEPLOY_VERSION__
+ */
+ protected $user;
+
/**
* Display the view.
*
@@ -83,11 +89,6 @@ public function display($tpl = null)
$this->form = $model->getForm();
$this->return_page = $model->getReturnPage();
- // Check for errors.
- if (\count($errors = $model->getErrors())) {
- throw new GenericDataException(implode("\n", $errors), 500);
- }
-
if (empty($this->item->id)) {
$authorised = $user->authorise('core.create', 'com_weblinks') || \count($user->getAuthorisedCategories('com_weblinks', 'core.create'));
} else {
diff --git a/src/components/com_weblinks/src/View/Weblink/HtmlView.php b/src/components/com_weblinks/src/View/Weblink/HtmlView.php
index 566d70b21d3..fed09204b7f 100644
--- a/src/components/com_weblinks/src/View/Weblink/HtmlView.php
+++ b/src/components/com_weblinks/src/View/Weblink/HtmlView.php
@@ -10,11 +10,12 @@
namespace Joomla\Component\Weblinks\Site\View\Weblink;
-use Joomla\CMS\Event\Content;
+use Joomla\CMS\Event\Content\AfterDisplayEvent;
+use Joomla\CMS\Event\Content\AfterTitleEvent;
+use Joomla\CMS\Event\Content\BeforeDisplayEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
-use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Component\Weblinks\Site\Model\WeblinkModel;
// phpcs:disable PSR1.Files.SideEffects
@@ -65,15 +66,20 @@ public function display($tpl = null)
$app = Factory::getApplication();
/* @var WeblinkModel $model */
- $model = $this->getModel();
- $this->item = $model->getItem();
- $this->state = $model->getState();
- $this->params = $this->state->get('params');
-
- $errors = $model->getErrors();
+ $model = $this->getModel();
+
+ try {
+ $this->item = $model->getItem();
+ $this->state = $model->getState();
+ $this->params = $this->state->get('params');
+ } catch (\Exception $e) {
+ // Handle 404 error if weblink item not found
+ if ($e->getCode() === 404) {
+ throw $e;
+ }
- if (\count($errors) > 0) {
- $this->handleModelErrors($errors);
+ // Otherwise, it is database runtime error, and we will throw error 500
+ throw new GenericDataException($e->getMessage(), 500, $e);
}
// Create a shortcut for $item.
@@ -84,58 +90,24 @@ public function display($tpl = null)
$item->params->merge($temp);
$offset = $this->state->get('list.offset');
- $dispatcher = $this->getDispatcher();
-
- // Process the content plugins.
- PluginHelper::importPlugin('content', null, true, $dispatcher);
-
- $contentEventArguments = [
- 'context' => 'com_weblinks.weblink',
- 'subject' => $item,
- 'params' => $item->params,
- 'page' => $offset,
- ];
+ $dispatcher = $app->getDispatcher();
+ $item->event = new \stdClass();
+ $item->event->afterDisplayTitle = '';
+ $item->event->beforeDisplayContent = '';
+ $item->event->afterDisplayContent = '';
- $dispatcher->dispatch(
- 'onContentPrepare',
- new Content\ContentPrepareEvent('onContentPrepare', $contentEventArguments)
- );
+ $eventAfterTitleArgs = ['context' => 'com_weblinks.weblink', 'subject' => $item, 'params' => $item->params, 'offset' => $offset];
+ $eventAfterTitle = AfterTitleEvent::create('onContentAfterTitle', $eventAfterTitleArgs);
+ $dispatcher->dispatch('onContentAfterTitle', $eventAfterTitle);
- // Extra content from events
- $item->event = new \stdClass();
- $contentEvents = [
- 'afterDisplayTitle' => new Content\AfterTitleEvent('onContentAfterTitle', $contentEventArguments),
- 'beforeDisplayContent' => new Content\BeforeDisplayEvent('onContentBeforeDisplay', $contentEventArguments),
- 'afterDisplayContent' => new Content\AfterDisplayEvent('onContentAfterDisplay', $contentEventArguments),
- ];
+ $eventBeforeDisplayArgs = ['context' => 'com_weblinks.weblink', 'subject' => $item, 'params' => $item->params, 'offset' => $offset];
+ $eventBeforeDisplay = BeforeDisplayEvent::create('onContentBeforeDisplay', $eventBeforeDisplayArgs);
+ $dispatcher->dispatch('onContentBeforeDisplay', $eventBeforeDisplay);
- foreach ($contentEvents as $resultKey => $event) {
- $results = $dispatcher->dispatch($event->getName(), $event)->getArgument('result', []);
-
- $item->event->{$resultKey} = $results ? trim(implode("\n", $results)) : '';
- }
+ $eventAfterDisplayArgs = ['context' => 'com_weblinks.weblink', 'subject' => $item, 'params' => $item->params, 'offset' => $offset];
+ $eventAfterDisplay = AfterDisplayEvent::create('onContentAfterDisplay', $eventAfterDisplayArgs);
+ $dispatcher->dispatch('onContentAfterDisplay', $eventAfterDisplay);
parent::display($tpl);
}
-
- /**
- * Handle errors returned by model
- *
- * @param array $errors
- *
- * @return void
- * @throws \Exception
- */
- private function handleModelErrors(array $errors): void
- {
- foreach ($errors as $error) {
- // Throws 404 error if weblink item not found
- if ($error instanceof \Exception && $error->getCode() === 404) {
- throw $error;
- }
- }
-
- // Otherwise, it is database runtime error, and we will throw error 500
- throw new GenericDataException(implode("\n", $errors), 500);
- }
}
diff --git a/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php b/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php
index 5292eebc4a3..c207e73511c 100644
--- a/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php
+++ b/src/plugins/editors-xtd/weblink/src/Extension/Weblink.php
@@ -16,7 +16,6 @@
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Language\Text;
-use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\Session;
use Joomla\Database\DatabaseInterface;
@@ -53,14 +52,14 @@ public function __construct(DispatcherInterface $dispatcher, array $config, CMSA
/**
* Display the button
- *
- * @param string $name The name of the button to add
- *
- * @return CMSObject The button options as JObject
- *
- * @since __DEPLOY_VERSION__
- */
- public function onDisplay($name)
+ *
+ * @param string $name The name of the button to add
+ *
+ * @return ?object The button options as stdClass object or null
+ *
+ * @since __DEPLOY_VERSION__
+ */
+ public function onDisplay($name): ?object
{
$user = $this->getApplication()->getIdentity();
@@ -73,7 +72,7 @@ public function onDisplay($name)
$link = 'index.php?option=com_weblinks&view=weblinks&layout=modal&tmpl=component&'
. Session::getFormToken() . '=1&editor=' . $name;
- $button = new CMSObject();
+ $button = new \stdClass();
$button->modal = true;
$button->link = $link;
$button->text = Text::_('PLG_EDITORS-XTD_WEBLINK_BUTTON_WEBLINK');
@@ -93,5 +92,7 @@ public function onDisplay($name)
return $button;
}
+
+ return null; // return null if conditions are not met
}
}
diff --git a/src/plugins/finder/weblinks/src/Extension/Weblinks.php b/src/plugins/finder/weblinks/src/Extension/Weblinks.php
index 0341ce8af13..3f4e8b618df 100644
--- a/src/plugins/finder/weblinks/src/Extension/Weblinks.php
+++ b/src/plugins/finder/weblinks/src/Extension/Weblinks.php
@@ -16,6 +16,7 @@
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Component\ComponentHelper;
+use Joomla\CMS\Factory;
use Joomla\CMS\Table\Table;
use Joomla\Component\Finder\Administrator\Indexer\Adapter;
use Joomla\Component\Finder\Administrator\Indexer\Helper;
@@ -294,7 +295,8 @@ protected function index(Result $item)
$item->addTaxonomy('Type', 'Web Link');
// Add the category taxonomy data.
- $categories = Categories::getInstance('com_weblinks', ['published' => false, 'access' => false]);
+ $component = Factory::getApplication()->bootComponent('com_weblinks');
+ $categories = $component->getCategory(['published' => false, 'access' => false]);
$category = $categories->get($item->catid);
// Category does not exist, stop here
diff --git a/src/plugins/search/weblinks/src/Extension/Weblinks.php b/src/plugins/search/weblinks/src/Extension/Weblinks.php
index 47149c3f54d..0d722745d45 100644
--- a/src/plugins/search/weblinks/src/Extension/Weblinks.php
+++ b/src/plugins/search/weblinks/src/Extension/Weblinks.php
@@ -14,7 +14,6 @@
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
-use Joomla\Component\Search\Administrator\Helper\SearchHelper;
use Joomla\Component\Weblinks\Site\Helper\RouteHelper;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\DatabaseInterface;
@@ -228,11 +227,7 @@ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = nu
$rows[$key]->href = RouteHelper::getWeblinkRoute($row->slug, $row->catslug);
}
- foreach ($rows as $weblink) {
- if (SearchHelper::checkNoHTML($weblink, $searchText, ['url', 'text', 'title'])) {
- $return[] = $weblink;
- }
- }
+ $return = $rows;
}
return $return;