Skip to content

Commit

Permalink
Only start with main component helper for now
Browse files Browse the repository at this point in the history
  • Loading branch information
joomdonation committed Jun 10, 2017
1 parent ab17237 commit 05ecc31
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

defined('_JEXEC') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\Registry\Registry;
Expand Down Expand Up @@ -341,9 +340,17 @@ public static function getSupportedExtension($extensionName)
$result->def('associationssupport', false);
$result->def('helper', null);

$componentAssociationsHelperClassName = ComponentHelper::getHelperClassName($extensionName, 'associations');
// Check if associations helper exists
if (!file_exists(JPATH_ADMINISTRATOR . '/components/' . $extensionName . '/helpers/associations.php'))
{
return $result;
}

require_once JPATH_ADMINISTRATOR . '/components/' . $extensionName . '/helpers/associations.php';

$componentAssociationsHelperClassName = self::getExtensionHelperClassName($extensionName);

if (!$componentAssociationsHelperClassName)
if (!class_exists($componentAssociationsHelperClassName, false))
{
return $result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ public static function addSubmenu($extension)
$section = $parts[1];
}


$cName = ComponentHelper::getHelperClassName($component);
// Try to find the component helper.
$cName = ComponentHelper::getComponentHelperClassName($component);

if ($cName && is_callable(array($cName, 'addSubmenu')))
{

$lang = \JFactory::getLanguage();

// Loading language file from the administrator/language directory then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public function countItems(&$items, $extension)
}

// Try to find the component helper.
$cName = ComponentHelper::getHelperClassName($component);
$cName = ComponentHelper::getComponentHelperClassName($component);

if ($cName && is_callable(array($cName, 'countItems')))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ public static function getCategoryAssociations($id = 0, $extension = 'com_conten
{
// Load route helper
jimport('helper.route', JPATH_COMPONENT_SITE);
$helperClassname = \Joomla\CMS\Component\ComponentHelper::getHelperClassName($extension, 'Route', 'Site');

$helperClassname = ucfirst(substr($extension, 4)) . 'HelperRoute';

$associations = CategoriesHelper::getAssociations($id, $extension);

foreach ($associations as $tag => $item)
{
if ($helperClassname && is_callable(array($helperClassname, 'getCategoryRoute')))
if (class_exists($helperClassname) && is_callable(array($helperClassname, 'getCategoryRoute')))
{
$return[$tag] = $helperClassname::getCategoryRoute($item, $tag);
}
Expand Down
4 changes: 3 additions & 1 deletion administrator/components/com_fields/helpers/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

JLoader::register('JFolder', JPATH_LIBRARIES . '/joomla/filesystem/folder.php');

use Joomla\CMS\Component\ComponentHelper;

/**
* FieldsHelper
*
Expand Down Expand Up @@ -43,7 +45,7 @@ public static function extract($contextString, $item = null)

$component = $parts[0];

$cName = \Joomla\CMS\Component\ComponentHelper::getHelperClassName($component);
$cName = ComponentHelper::getComponentHelperClassName($component);

if ($cName && is_callable(array($cName, 'validateSection')))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

JFormHelper::loadFieldClass('list');

use Joomla\CMS\Component\ComponentHelper;

/**
* Fields Contexts
*
Expand Down Expand Up @@ -43,7 +45,7 @@ protected function getOptions()
{
$parts = explode('.', $this->value);

$cName = \Joomla\CMS\Component\ComponentHelper::getHelperClassName($parts[0]);
$cName = ComponentHelper::getComponentHelperClassName($parts[0]);

$contexts = array();

Expand All @@ -54,7 +56,7 @@ protected function getOptions()

if (!$contexts || !is_array($contexts) || count($contexts) == 1)
{
return array();
$contexts = array();
}

return $contexts;
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_tags/Model/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ public function countItems(&$items, $extension)
}

// Try to find the component helper.
$cName = ComponentHelper::getHelperClassName($component);
$cName = ComponentHelper::getComponentHelperClassName($component);

if ($cName && is_callable(array($cName, 'countTagItems')))
{
Expand Down
7 changes: 4 additions & 3 deletions libraries/src/CMS/Categories/Categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Language\Multilanguage;

/**
Expand Down Expand Up @@ -141,12 +140,14 @@ public static function getInstance($extension, $options = array())

if (!class_exists($classname))
{
$classname = ComponentHelper::getHelperClassName($component, 'category', 'Site');
$path = JPATH_SITE . '/components/' . $component . '/helpers/category.php';

if (!$classname)
if (!is_file($path))
{
return false;
}

include_once $path;
}

// Check for a possible service from the container otherwise manually instantiate the class
Expand Down
48 changes: 20 additions & 28 deletions libraries/src/CMS/Component/ComponentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,53 +567,45 @@ public static function getComponentName($object, $alternativeName)
/**
* Method to get helper class for a component
*
* @param string $option The name of component to get helper class, for example com_content
* @param string $helper The type of helper to get like helper (main component helper), association, route, associations..
* @param string $appName Name of application to get helper class (Site or Administrator)
* @param string $option The name of component to get helper class, for example com_content
*
* @return bool|string The class name if exists, false otherwise
*/
public static function getHelperClassName($option, $helper = 'helper', $appName = 'Administrator')
public static function getComponentHelperClassName($option)
{
jimport('joomla.filesystem.path');

$componentName = str_replace('com_', '', $option);
$helper = ucfirst($helper);

if ($helper == 'Helper')
{
// Main component helper class name, like ContentHelper
$className = ucfirst($componentName) . 'Helper';
}
else
// Check and make sure component exists to avoid warning
if (!self::isInstalled($option))
{
// Specific type component class name like ContentAssociationsHelper
$className = ucfirst($componentName) . $helper . 'Helper';;
return false;
}

$componentName = str_replace('com_', '', $option);

// If this is a namespace component, try to find a helper namespace class
if ($componentNamespace = self::getComponent($option)->namespace)
{
$fqcn = $componentNamespace . '\\' . ucfirst($appName) . '\\Helper\\' . $className;
$className = $componentNamespace . '\\Administrator\\Helper\\' . ucfirst($componentName) . 'Helper';

if (class_exists($fqcn))
if (class_exists($className))
{
return $fqcn;
return $className;
}
}

// Fall back to find a none namespace helper class
$rootPath = constant('JPATH_' . strtoupper($appName));

$file = \JPath::clean($rootPath . '/components/' . $option . '/helpers/' . $helper . '.php');

if (file_exists($file))
else
{
\JLoader::register($className, $file);
$file = \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $option . '/helpers/' . $componentName . '.php');

if (class_exists($className))
if (file_exists($file))
{
return $className;
$className = ucfirst($componentName) . 'Helper';
\JLoader::register($className, $file);

if (class_exists($className))
{
return $className;
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions modules/mod_languages/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ public static function getList(&$params)
}

// Load component associations
$class = \Joomla\CMS\Component\ComponentHelper::getHelperClassName($app->input->get('option'), 'association', 'Site');
$class = str_replace('com_', '', $app->input->get('option')) . 'HelperAssociation';
JLoader::register($class, JPATH_COMPONENT_SITE . '/helpers/association.php');

if ($class && is_callable(array($class, 'getAssociations')))
if (class_exists($class) && is_callable(array($class, 'getAssociations')))
{
$cassociations = call_user_func(array($class, 'getAssociations'));
}
Expand Down

0 comments on commit 05ecc31

Please sign in to comment.