Skip to content

Commit

Permalink
[4.0] Check on the component if the categories support is available (#…
Browse files Browse the repository at this point in the history
…20692)

* Check on the component if the categories support is available

* add check

* Move getAssociations to interface

* Revert

* Change to $cassociations

* CS
  • Loading branch information
laoneo authored Jul 13, 2018
1 parent ae444bb commit 77c731f
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 17 deletions.
18 changes: 14 additions & 4 deletions administrator/components/com_categories/Model/CategoriesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
20 changes: 16 additions & 4 deletions administrator/components/com_categories/Model/CategoryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
15 changes: 15 additions & 0 deletions administrator/components/com_contact/helpers/associations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
16 changes: 16 additions & 0 deletions administrator/components/com_content/Helper/AssociationsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
*
Expand Down
15 changes: 15 additions & 0 deletions administrator/components/com_menus/Helper/AssociationsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
15 changes: 15 additions & 0 deletions administrator/components/com_newsfeeds/helpers/associations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
12 changes: 12 additions & 0 deletions libraries/src/Association/AssociationExtensionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
20 changes: 15 additions & 5 deletions modules/mod_languages/Helper/LanguagesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));
}
}
}

Expand Down
19 changes: 15 additions & 4 deletions plugins/system/languagefilter/languagefilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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...
Expand Down

0 comments on commit 77c731f

Please sign in to comment.