Skip to content

Commit

Permalink
Call namespace helper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
joomdonation committed Jun 7, 2017
1 parent b8de81f commit f4083bc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 46 deletions.
20 changes: 0 additions & 20 deletions administrator/components/com_banners/helpers/banners.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

defined('JPATH_BASE') or die;

JLoader::register('BannersHelper', JPATH_ADMINISTRATOR . '/components/com_banners/helpers/banners.php');
use Joomla\Component\Banners\Administrator\Helper\BannersHelper;

JFormHelper::loadFieldClass('list');

Expand Down
39 changes: 22 additions & 17 deletions administrator/components/com_categories/Helper/CategoriesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace Joomla\Component\Categories\Administrator\Helper;

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Table\Table;
Expand Down Expand Up @@ -49,29 +50,33 @@ public static function addSubmenu($extension)

// Try to find the component helper.
$eName = str_replace('com_', '', $component);
$file = \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component . '/helpers/' . $eName . '.php');
$namespace = ComponentHelper::getComponent($component)->namespace;

if (file_exists($file))
if ($namespace)
{
$prefix = ucfirst(str_replace('com_', '', $component));
$cName = $prefix . 'Helper';

\JLoader::register($cName, $file);
$cName = $namespace.'\\Administrator\\Helper\\'.ucfirst($eName.'Helper');
}
else
{
$file = \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component . '/helpers/' . $eName . '.php');

if (class_exists($cName))
if (file_exists($file))
{
if (is_callable(array($cName, 'addSubmenu')))
{
$lang = \JFactory::getLanguage();
$cName = ucfirst($eName) . 'Helper';
\JLoader::register($cName, $file);
}
}

if (!empty($cName) && class_exists($cName) && is_callable(array($cName, 'addSubmenu')))
{
$lang = \JFactory::getLanguage();

// Loading language file from the administrator/language directory then
// loading language file from the administrator/components/*extension*/language directory
$lang->load($component, JPATH_BASE, null, false, true)
|| $lang->load($component, \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component), null, false, true);
// Loading language file from the administrator/language directory then
// loading language file from the administrator/components/*extension*/language directory
$lang->load($component, JPATH_BASE, null, false, true)
|| $lang->load($component, \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component), null, false, true);

call_user_func(array($cName, 'addSubmenu'), 'categories' . (isset($section) ? '.' . $section : ''));
}
}
call_user_func(array($cName, 'addSubmenu'), 'categories' . (isset($section) ? '.' . $section : ''));
}
}

Expand Down
24 changes: 16 additions & 8 deletions administrator/components/com_tags/Model/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,19 +360,27 @@ public function countItems(&$items, $extension)

// Try to find the component helper.
$eName = str_replace('com_', '', $component);
$file = \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component . '/helpers/' . $eName . '.php');

if (file_exists($file))
{
$prefix = ucfirst(str_replace('com_', '', $component));
$cName = $prefix . 'Helper';
$namespace = ComponentHelper::getComponent($component)->namespace;

\JLoader::register($cName, $file);
if ($namespace)
{
$cName = $namespace.'\\Administrator\\Helper\\'.ucfirst($eName.'Helper');
}
else
{
$file = \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component . '/helpers/' . $eName . '.php');

if (class_exists($cName) && is_callable(array($cName, 'countTagItems')))
if (file_exists($file))
{
$cName::countTagItems($items, $extension);
$cName = ucfirst($eName) . 'Helper';
\JLoader::register($cName, $file);
}
}

if (!empty($cName) && class_exists($cName) && is_callable(array($cName, 'countTagItems')))
{
$cName::countTagItems($items, $extension);
}
}
}

0 comments on commit f4083bc

Please sign in to comment.