diff --git a/src/administrator/components/com_weblinks/services/provider.php b/src/administrator/components/com_weblinks/services/provider.php
index 1f78a99..059bde7 100644
--- a/src/administrator/components/com_weblinks/services/provider.php
+++ b/src/administrator/components/com_weblinks/services/provider.php
@@ -16,6 +16,7 @@ use Joomla\CMS\Extension\Service\Provider\CategoryFactory;
use Joomla\CMS\Extension\Service\Provider\ComponentDispatcherFactory;
use Joomla\CMS\Extension\Service\Provider\MVCFactory;
use Joomla\CMS\Extension\Service\Provider\RouterFactory;
+use Joomla\CMS\HTML\Registry;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\Component\Weblinks\Administrator\Extension\WeblinksComponent;
use Joomla\DI\Container;
@@ -47,6 +48,7 @@ return new class implements ServiceProviderInterface
ComponentInterface::class,
function (Container $container) {
$component = new WeblinksComponent($container->get(ComponentDispatcherFactoryInterface::class));
+ $component->setRegistry($container->get(Registry::class));
$component->setMVCFactory($container->get(MVCFactoryInterface::class));
$component->setCategoryFactory($container->get(CategoryFactoryInterface::class));
$component->setRouterFactory($container->get(RouterFactoryInterface::class));
diff --git a/src/administrator/components/com_weblinks/src/Extension/WeblinksComponent.php b/src/administrator/components/com_weblinks/src/Extension/WeblinksComponent.php
index 74aeb3e..ffa7d65 100644
--- a/src/administrator/components/com_weblinks/src/Extension/WeblinksComponent.php
+++ b/src/administrator/components/com_weblinks/src/Extension/WeblinksComponent.php
@@ -11,15 +11,20 @@ namespace Joomla\Component\Weblinks\Administrator\Extension;
defined('JPATH_PLATFORM') or die;
+use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Association\AssociationServiceInterface;
use Joomla\CMS\Association\AssociationServiceTrait;
use Joomla\CMS\Categories\CategoryServiceInterface;
use Joomla\CMS\Categories\CategoryServiceTrait;
use Joomla\CMS\Component\Router\RouterServiceInterface;
use Joomla\CMS\Component\Router\RouterServiceTrait;
+use Joomla\CMS\Extension\BootableExtensionInterface;
use Joomla\CMS\Extension\MVCComponent;
+use Joomla\CMS\HTML\HTMLRegistryAwareTrait;
use Joomla\CMS\Tag\TagServiceInterface;
use Joomla\CMS\Tag\TagServiceTrait;
+use Joomla\Component\Weblinks\Administrator\Service\HTML\AdministratorService;
+use Psr\Container\ContainerInterface;
/**
* Component class for com_contact
@@ -27,10 +32,11 @@ use Joomla\CMS\Tag\TagServiceTrait;
* @since 4.0.0
*/
class WeblinksComponent extends MVCComponent implements CategoryServiceInterface, AssociationServiceInterface,
- TagServiceInterface, RouterServiceInterface
+ TagServiceInterface, RouterServiceInterface, BootableExtensionInterface
{
use CategoryServiceTrait;
use AssociationServiceTrait;
+ use HTMLRegistryAwareTrait;
use RouterServiceTrait;
use CategoryServiceTrait, TagServiceTrait
{
@@ -38,6 +44,24 @@ class WeblinksComponent extends MVCComponent implements CategoryServiceInterface
CategoryServiceTrait::getStateColumnForSection insteadof TagServiceTrait;
}
+ /**
+ * Booting the extension. This is the function to set up the environment of the extension like
+ * registering new class loaders, etc.
+ *
+ * If required, some initial set up can be done from services of the container, eg.
+ * registering HTML services.
+ *
+ * @param ContainerInterface $container The container
+ *
+ * @return void
+ *
+ * @since 4.0.0
+ */
+ public function boot(ContainerInterface $container)
+ {
+ $this->getRegistry()->register('weblinksadministrator', new AdministratorService);
+ }
+
/**
* Returns the table for the count items functions for the given section.
*
diff --git a/src/administrator/components/com_weblinks/src/Service/HTML/AdministratorService.php b/src/administrator/components/com_weblinks/src/Service/HTML/AdministratorService.php
new file mode 100644
index 0000000..2577b8f
--- /dev/null
+++ b/src/administrator/components/com_weblinks/src/Service/HTML/AdministratorService.php
@@ -0,0 +1,113 @@
+
+ * @license GNU General Public License version 2 or later; see LICENSE.txt
+ */
+
+namespace Joomla\Component\Weblinks\Administrator\Service\HTML;
+
+\defined('_JEXEC') or die;
+
+use Joomla\CMS\Factory;
+use Joomla\CMS\Language\Associations;
+use Joomla\CMS\Language\LanguageHelper;
+use Joomla\CMS\Language\Text;
+use Joomla\CMS\Layout\LayoutHelper;
+use Joomla\CMS\Router\Route;
+use Joomla\Database\ParameterType;
+
+/**
+ * Weblinks HTML helper class.
+ *
+ * @since 1.6
+ */
+class AdministratorService
+{
+ /**
+ * Get the associated language flags
+ *
+ * @param integer $weblinkid The item id to search associations
+ *
+ * @return string The language HTML
+ *
+ * @throws \Exception
+ */
+ public function association($weblinkid)
+ {
+ // Defaults
+ $html = '';
+
+ // Get the associations
+ if ($associations = Associations::getAssociations('com_weblinks', '#__weblinks', 'com_weblinks.item', $weblinkid))
+ {
+ foreach ($associations as $tag => $associated)
+ {
+ $associations[$tag] = (int) $associated->id;
+ }
+
+ // Get the associated contact items
+ $db = Factory::getDbo();
+ $query = $db->getQuery(true)
+ ->select(
+ [
+ $db->quoteName('c.id'),
+ $db->quoteName('c.title', 'title'),
+ $db->quoteName('l.sef', 'lang_sef'),
+ $db->quoteName('lang_code'),
+ $db->quoteName('cat.title', 'category_title'),
+ $db->quoteName('l.image'),
+ $db->quoteName('l.title', 'language_title'),
+ ]
+ )
+ ->from($db->quoteName('#__weblinks', 'c'))
+ ->join('LEFT', $db->quoteName('#__categories', 'cat'), $db->quoteName('cat.id') . ' = ' . $db->quoteName('c.catid'))
+ ->join('LEFT', $db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code'))
+ ->whereIn($db->quoteName('c.id'), array_values($associations))
+ ->where($db->quoteName('c.id') . ' != :id')
+ ->bind(':id', $weblinkid, ParameterType::INTEGER);
+ $db->setQuery($query);
+
+ try
+ {
+ $items = $db->loadObjectList('id');
+ }
+ catch (\RuntimeException $e)
+ {
+ throw new \Exception($e->getMessage(), 500, $e);
+ }
+
+ if ($items)
+ {
+ $languages = LanguageHelper::getContentLanguages(array(0, 1));
+ $content_languages = array_column($languages, 'lang_code');
+
+ foreach ($items as &$item)
+ {
+ if (in_array($item->lang_code, $content_languages))
+ {
+ $text = $item->lang_code;
+ $url = Route::_('index.php?option=com_weblinks&task=weblink.edit&id=' . (int) $item->id);
+ $tooltip = '' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '
'
+ . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '
' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title);
+ $classes = 'badge bg-secondary';
+
+ $item->link = '' . $text . ''
+ . '