diff --git a/src/administrator/components/com_weblinks/script.php b/src/administrator/components/com_weblinks/script.php index 20b7bd38310..cd992de2c34 100644 --- a/src/administrator/components/com_weblinks/script.php +++ b/src/administrator/components/com_weblinks/script.php @@ -113,16 +113,20 @@ public function install($parent) // Set the location in the tree $category->setLocation(1, 'last-child'); - // Check to make sure our data is valid - if (!$category->check()) { - Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError())); + try { + // Check to make sure our data is valid + $category->check(); + } catch (\Exception $e) { + Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $e->getMessage()), 'error'); return; } - // Now store the category - if (!$category->store(true)) { - Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $category->getError())); + try { + // Now store the category + $category->store(true); + } catch (\Exception $e) { + Factory::getApplication()->enqueueMessage(Text::sprintf('COM_WEBLINKS_ERROR_INSTALL_CATEGORY', $e->getMessage()), 'error'); return; } diff --git a/src/administrator/components/com_weblinks/src/Service/HTML/Icon.php b/src/administrator/components/com_weblinks/src/Service/HTML/Icon.php index cfce3eded61..48d14f0b33f 100644 --- a/src/administrator/components/com_weblinks/src/Service/HTML/Icon.php +++ b/src/administrator/components/com_weblinks/src/Service/HTML/Icon.php @@ -20,6 +20,7 @@ use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; use Joomla\CMS\Uri\Uri; +use Joomla\CMS\User\UserFactoryInterface; use Joomla\Component\Weblinks\Site\Helper\RouteHelper; use Joomla\Registry\Registry; @@ -115,7 +116,8 @@ public function edit($weblink, $params, $attribs = [], $legacy = false) && $weblink->checked_out && $weblink->checked_out !== $user->get('id') ) { - $checkoutUser = Factory::getUser($weblink->checked_out); + $userFactory = Factory::getContainer()->get(UserFactoryInterface::class); + $checkoutUser = $userFactory->loadUserById($weblink->checked_out); $date = HTMLHelper::_('date', $weblink->checked_out_time); $tooltip = Text::sprintf('COM_WEBLINKS_CHECKED_OUT_BY', $checkoutUser->name) . '
' . $date; diff --git a/src/administrator/components/com_weblinks/src/Table/WeblinkTable.php b/src/administrator/components/com_weblinks/src/Table/WeblinkTable.php index 9de7c471089..7f496a39ecc 100644 --- a/src/administrator/components/com_weblinks/src/Table/WeblinkTable.php +++ b/src/administrator/components/com_weblinks/src/Table/WeblinkTable.php @@ -126,8 +126,7 @@ public function store($updateNulls = true) $table->load(['language' => $this->language, 'alias' => $this->alias, 'catid' => (int) $this->catid]) && ($table->id != $this->id || $this->id == 0) ) { - $this->setError(Text::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS')); - return false; + throw new \Exception(Text::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS')); } // Convert IDN urls to punycode @@ -145,14 +144,12 @@ public function store($updateNulls = true) public function check() { if (InputFilter::checkAttribute(['href', $this->url])) { - $this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL')); - return false; + throw new \Exception(Text::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL')); } // Check for valid name if (trim($this->title) === '') { - $this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_TITLE')); - return false; + throw new \Exception(Text::_('COM_WEBLINKS_ERR_TABLES_TITLE')); } // Check for existing name @@ -169,8 +166,7 @@ public function check() $db->setQuery($query); $xid = (int) $db->loadResult(); if ($xid && $xid != (int) $this->id) { - $this->setError(Text::_('COM_WEBLINKS_ERR_TABLES_NAME')); - return false; + throw new \Exception(Text::_('COM_WEBLINKS_ERR_TABLES_NAME')); } if (empty($this->alias)) { @@ -184,8 +180,7 @@ public function check() // Check the publish down date is not earlier than publish up. if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) { - $this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH')); - return false; + throw new \Exception(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH')); } /* diff --git a/src/administrator/components/com_weblinks/src/View/Weblink/HtmlView.php b/src/administrator/components/com_weblinks/src/View/Weblink/HtmlView.php index e452ddd0f65..789eb215d03 100644 --- a/src/administrator/components/com_weblinks/src/View/Weblink/HtmlView.php +++ b/src/administrator/components/com_weblinks/src/View/Weblink/HtmlView.php @@ -19,10 +19,10 @@ use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Text; -use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Weblinks\Administrator\Model\WeblinkModel; +use Joomla\Registry\Registry; /** * View to edit a weblink. @@ -48,7 +48,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\CMS\Object\CMSObject + * @var Registry */ protected $state; @@ -67,11 +67,6 @@ public function display($tpl = null) $this->item = $model->getItem(); $this->form = $model->getForm(); - // Check for errors. - if (\count($errors = $model->getErrors())) { - throw new GenericDataException(implode("\n", $errors), 500); - } - // If we are forcing a language in modal (used for associations). if ($this->getLayout() === 'modal' && $forcedLanguage = Factory::getApplication()->getInput()->get('forcedLanguage', '', 'cmd')) { // Set the language field to the forcedLanguage and disable changing it. @@ -90,6 +85,18 @@ public function display($tpl = null) parent::display($tpl); } + /** + * Get the item ID. + * + * @return int + * + * @since __DEPLOY_VERSION__ + */ + public function getItemId(): int + { + return (int) $this->item->id; + } + /** * Add the page title and toolbar. * diff --git a/src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php b/src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php index 58cf549de6c..aca82a83ea1 100644 --- a/src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php +++ b/src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php @@ -18,10 +18,11 @@ use Joomla\CMS\Factory; use Joomla\CMS\Helper\ContentHelper; use Joomla\CMS\Language\Text; -use Joomla\CMS\MVC\View\GenericDataException; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Pagination\Pagination; use Joomla\CMS\Toolbar\ToolbarHelper; use Joomla\Component\Weblinks\Administrator\Model\WeblinksModel; +use Joomla\Registry\Registry; /** * View class for a list of weblinks. @@ -47,7 +48,7 @@ class HtmlView extends BaseHtmlView /** * The model state * - * @var \Joomla\CMS\Object\CMSObject + * @var Registry */ protected $state; @@ -91,12 +92,7 @@ public function display($tpl = null) $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); - // Check for errors. - if (\count($errors = $model->getErrors())) { - throw new GenericDataException(implode("\n", $errors), 500); - } - - if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) { + if (!\count($this->items) && $this->isEmptyState = $model->getIsEmptyState()) { $this->setLayout('emptystate'); } @@ -122,6 +118,42 @@ public function display($tpl = null) parent::display($tpl); } + /** + * Get the items. + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + public function getItems(): array + { + return $this->items; + } + + /** + * Get the pagination object. + * + * @return Pagination + * + * @since __DEPLOY_VERSION__ + */ + public function getPagination(): Pagination + { + return $this->pagination; + } + + /** + * Get the model state. + * + * @return Registry + * + * @since __DEPLOY_VERSION__ + */ + public function getState(): Registry + { + return $this->state; + } + /** * Add the page title and toolbar. * diff --git a/src/administrator/components/com_weblinks/tmpl/weblink/modal.php b/src/administrator/components/com_weblinks/tmpl/weblink/modal.php index 1e2db0ff8ec..d795d90794d 100644 --- a/src/administrator/components/com_weblinks/tmpl/weblink/modal.php +++ b/src/administrator/components/com_weblinks/tmpl/weblink/modal.php @@ -16,17 +16,21 @@ /** @var \Joomla\Component\Weblinks\Administrator\View\Weblink\HtmlView $this */ -HTMLHelper::_('bootstrap.tooltip', '.hasTooltip', array('placement' => 'bottom')); +HTMLHelper::_('bootstrap.tooltip', '.hasTooltip', ['placement' => 'bottom']); + // @deprecated 4.0 the function parameter, the inline js and the buttons are not needed since 3.7.0. -$function = Factory::getApplication()->getInput()->getCmd('function', 'jEditWeblink_' . (int) $this->item->id); +$function = Factory::getApplication()->getInput()->getCmd('function', 'jEditWeblink_' . $this->getItemId()); + // Function to update input title when changed -$this->getDocument()->addScriptDeclaration(' +$wa = Factory::getApplication()->getDocument()->getWebAssetManager(); +$script = <<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;