diff --git a/administrator/components/com_categories/Model/CategoriesModel.php b/administrator/components/com_categories/Model/CategoriesModel.php index 90e1fea22d684..9e10e94644a1b 100644 --- a/administrator/components/com_categories/Model/CategoriesModel.php +++ b/administrator/components/com_categories/Model/CategoriesModel.php @@ -10,6 +10,7 @@ defined('_JEXEC') or die; +use Joomla\CMS\Association\AssociationServiceInterface; use Joomla\CMS\Categories\CategoriesServiceInterface; use Joomla\CMS\Factory; use Joomla\CMS\MVC\Factory\MVCFactoryInterface; @@ -326,15 +327,24 @@ public function getAssoc() if (!$assoc || !$component || !$cname) { $assoc = false; + + return $assoc; } - else + + $componentObject = $this->bootComponent($component); + + if ($componentObject instanceof AssociationServiceInterface && $componentObject instanceof CategoriesServiceInterface) { - $hname = $cname . 'HelperAssociation'; - \JLoader::register($hname, JPATH_SITE . '/components/' . $component . '/helpers/association.php'); + $assoc = true; - $assoc = class_exists($hname) && !empty($hname::$category_association); + return $assoc; } + $hname = $cname . 'HelperAssociation'; + \JLoader::register($hname, JPATH_SITE . '/components/' . $component . '/helpers/association.php'); + + $assoc = class_exists($hname) && !empty($hname::$category_association); + return $assoc; } diff --git a/administrator/components/com_categories/Model/CategoryModel.php b/administrator/components/com_categories/Model/CategoryModel.php index 9924dc1db4047..52060c77a18a1 100644 --- a/administrator/components/com_categories/Model/CategoryModel.php +++ b/administrator/components/com_categories/Model/CategoryModel.php @@ -10,7 +10,10 @@ defined('_JEXEC') or die; +use Joomla\CMS\Association\AssociationServiceInterface; +use Joomla\CMS\Categories\CategoriesServiceInterface; use Joomla\CMS\Component\ComponentHelper; +use Joomla\CMS\Factory; use Joomla\CMS\Helper\TagsHelper; use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\LanguageHelper; @@ -1281,15 +1284,24 @@ public function getAssoc() if (!$assoc || !$component || !$cname) { $assoc = false; + + return $assoc; } - else + + $componentObject = $this->bootComponent($component); + + if ($componentObject instanceof AssociationServiceInterface && $componentObject instanceof CategoriesServiceInterface) { - $hname = $cname . 'HelperAssociation'; - \JLoader::register($hname, JPATH_SITE . '/components/' . $component . '/helpers/association.php'); + $assoc = true; - $assoc = class_exists($hname) && !empty($hname::$category_association); + return $assoc; } + $hname = $cname . 'HelperAssociation'; + \JLoader::register($hname, JPATH_SITE . '/components/' . $component . '/helpers/association.php'); + + $assoc = class_exists($hname) && !empty($hname::$category_association); + return $assoc; } } diff --git a/administrator/components/com_contact/helpers/associations.php b/administrator/components/com_contact/helpers/associations.php index 9579418c06dba..53d45000d102e 100644 --- a/administrator/components/com_contact/helpers/associations.php +++ b/administrator/components/com_contact/helpers/associations.php @@ -47,6 +47,21 @@ class ContactAssociationsHelper extends AssociationExtensionHelper */ protected $associationsSupport = true; + /** + * Method to get the associations for a given item. + * + * @param integer $id Id of the item + * @param string $view Name of the view + * + * @return array Array of associations for the item + * + * @since __DEPLOY_VERSION__ + */ + public function getAssociationsForItem($id = 0, $view = null) + { + return \ContactHelperAssociation::getAssociations($id, $view); + } + /** * Get the associated items for an item * diff --git a/administrator/components/com_content/Helper/AssociationsHelper.php b/administrator/components/com_content/Helper/AssociationsHelper.php index 797f35da39bf1..b0d9cc6e0a356 100644 --- a/administrator/components/com_content/Helper/AssociationsHelper.php +++ b/administrator/components/com_content/Helper/AssociationsHelper.php @@ -14,6 +14,7 @@ use Joomla\CMS\Association\AssociationExtensionHelper; use Joomla\CMS\Language\Associations; use Joomla\CMS\Table\Table; +use Joomla\Component\Content\Site\Helper\AssociationHelper; /** * Content associations helper. @@ -49,6 +50,21 @@ class AssociationsHelper extends AssociationExtensionHelper */ protected $associationsSupport = true; + /** + * Method to get the associations for a given item. + * + * @param integer $id Id of the item + * @param string $view Name of the view + * + * @return array Array of associations for the item + * + * @since __DEPLOY_VERSION__ + */ + public function getAssociationsForItem($id = 0, $view = null) + { + return AssociationHelper::getAssociations($id, $view); + } + /** * Get the associated items for an item * diff --git a/administrator/components/com_menus/Helper/AssociationsHelper.php b/administrator/components/com_menus/Helper/AssociationsHelper.php index 2bcb02bcc1501..6e3ee1947e4b7 100644 --- a/administrator/components/com_menus/Helper/AssociationsHelper.php +++ b/administrator/components/com_menus/Helper/AssociationsHelper.php @@ -49,6 +49,21 @@ class AssociationsHelper extends AssociationExtensionHelper */ protected $associationsSupport = true; + /** + * Method to get the associations for a given item. + * + * @param integer $id Id of the item + * @param string $view Name of the view + * + * @return array Array of associations for the item + * + * @since __DEPLOY_VERSION__ + */ + public function getAssociationsForItem($id = 0, $view = null) + { + return []; + } + /** * Get the associated items for an item * diff --git a/administrator/components/com_newsfeeds/helpers/associations.php b/administrator/components/com_newsfeeds/helpers/associations.php index 49845cd473403..0240593dac9ae 100644 --- a/administrator/components/com_newsfeeds/helpers/associations.php +++ b/administrator/components/com_newsfeeds/helpers/associations.php @@ -47,6 +47,21 @@ class NewsfeedsAssociationsHelper extends AssociationExtensionHelper */ protected $associationsSupport = true; + /** + * Method to get the associations for a given item. + * + * @param integer $id Id of the item + * @param string $view Name of the view + * + * @return array Array of associations for the item + * + * @since __DEPLOY_VERSION__ + */ + public function getAssociationsForItem($id = 0, $view = null) + { + return \NewsfeedsAssociationsHelper::getAssociations($id, $view); + } + /** * Get the associated items for an item * diff --git a/libraries/src/Association/AssociationExtensionInterface.php b/libraries/src/Association/AssociationExtensionInterface.php index 599b8718438e6..6ebb71600754f 100644 --- a/libraries/src/Association/AssociationExtensionInterface.php +++ b/libraries/src/Association/AssociationExtensionInterface.php @@ -25,4 +25,16 @@ interface AssociationExtensionInterface * @since 3.7.0 */ public function hasAssociationsSupport(); + + /** + * Method to get the associations for a given item. + * + * @param integer $id Id of the item + * @param string $view Name of the view + * + * @return array Array of associations for the item + * + * @since __DEPLOY_VERSION__ + */ + public function getAssociationsForItem($id = 0, $view = null); } diff --git a/modules/mod_languages/Helper/LanguagesHelper.php b/modules/mod_languages/Helper/LanguagesHelper.php index 34a4087937aac..5aaecb34b03e2 100644 --- a/modules/mod_languages/Helper/LanguagesHelper.php +++ b/modules/mod_languages/Helper/LanguagesHelper.php @@ -11,6 +11,7 @@ defined('_JEXEC') or die; +use Joomla\CMS\Association\AssociationServiceInterface; use Joomla\CMS\Factory; use Joomla\CMS\Uri\Uri; use Joomla\CMS\Language\LanguageHelper; @@ -67,13 +68,22 @@ public static function getList(&$params) $associations = \MenusHelper::getAssociations($active->id); } - // Load component associations - $class = str_replace('com_', '', $app->input->get('option')) . 'HelperAssociation'; - \JLoader::register($class, JPATH_COMPONENT_SITE . '/helpers/association.php'); + $component = $app->bootComponent($app->input->get('option')); - if (class_exists($class) && is_callable(array($class, 'getAssociations'))) + if ($component instanceof AssociationServiceInterface) { - $cassociations = call_user_func(array($class, 'getAssociations')); + $cassociations = $component->getAssociationsExtension()->getAssociationsForItem(); + } + else + { + // Load component associations + $class = str_replace('com_', '', $app->input->get('option')) . 'HelperAssociation'; + \JLoader::register($class, JPATH_COMPONENT_SITE . '/helpers/association.php'); + + if (class_exists($class) && is_callable(array($class, 'getAssociations'))) + { + $cassociations = call_user_func(array($class, 'getAssociations')); + } } } diff --git a/plugins/system/languagefilter/languagefilter.php b/plugins/system/languagefilter/languagefilter.php index 48affdb5d98a1..3bb600ff2b67e 100644 --- a/plugins/system/languagefilter/languagefilter.php +++ b/plugins/system/languagefilter/languagefilter.php @@ -9,6 +9,7 @@ defined('_JEXEC') or die; +use Joomla\CMS\Association\AssociationServiceInterface; use Joomla\CMS\Uri\Uri; use Joomla\CMS\Factory; use Joomla\CMS\Router\Route; @@ -779,12 +780,22 @@ public function onAfterDispatch() // Load component associations. $option = $this->app->input->get('option'); - $cName = StringHelper::ucfirst(StringHelper::str_ireplace('com_', '', $option)) . 'HelperAssociation'; - JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php')); - if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) + $component = $this->app->bootComponent($option); + + if ($component instanceof AssociationServiceInterface) + { + $cassociations = $component->getAssociationsExtension()->getAssociationsForItem(); + } + else { - $cassociations = call_user_func(array($cName, 'getAssociations')); + $cName = StringHelper::ucfirst(StringHelper::str_ireplace('com_', '', $option)) . 'HelperAssociation'; + JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php')); + + if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) + { + $cassociations = call_user_func(array($cName, 'getAssociations')); + } } // For each language...