Skip to content

Commit

Permalink
Merge branch '4.0-dev' into preview
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragteapot committed May 9, 2018
2 parents 5b3768c + 4120a19 commit 80ed169
Show file tree
Hide file tree
Showing 45 changed files with 1,272 additions and 745 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

defined('_JEXEC') or die;

use Joomla\CMS\Association\AssociationExtensionInterface;
use Joomla\CMS\Association\AssociationServiceInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Layout\LayoutHelper;
Expand Down Expand Up @@ -130,6 +132,43 @@ public static function hasSupport($extensionName)
return in_array($extensionName, self::$supportedExtensionsList);
}

/**
* Loads the helper for the given class.
*
* @param string $extensionName The extension name with com_
*
* @return AssociationExtensionInterface|null
*
* @since __DEPLOY_VERSION__
*/
private static function loadHelper($extensionName)
{
$component = Factory::getApplication()->bootComponent($extensionName);

if ($component instanceof AssociationServiceInterface)
{
return $component->getAssociationsExtension();
}

// Check if associations helper exists
if (!file_exists(JPATH_ADMINISTRATOR . '/components/' . $extensionName . '/helpers/associations.php'))
{
return null;
}

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

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

if (!class_exists($componentAssociationsHelperClassName, false))
{
return null;
}

// Create an instance of the helper class
return new $componentAssociationsHelperClassName;
}

/**
* Get the extension specific helper class name
*
Expand Down Expand Up @@ -342,8 +381,7 @@ public static function getSupportedExtension($extensionName)
$result->def('associationssupport', false);
$result->def('helper', null);

// Get the associations class
$helper = Factory::getApplication()->bootComponent($extensionName)->getAssociationsExtension();
$helper = self::loadHelper($extensionName);

if (!$helper)
{
Expand Down
23 changes: 7 additions & 16 deletions administrator/components/com_categories/Model/CategoriesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

defined('_JEXEC') or die;

use Joomla\CMS\Categories\CategoriesServiceInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\MVC\Model\ListModel;
Expand Down Expand Up @@ -369,30 +371,19 @@ public function getItems()
*/
public function countItems(&$items, $extension)
{
$parts = explode('.', $extension, 2);
$component = $parts[0];
$section = null;
$parts = explode('.', $extension, 2);
$section = '';

if (count($parts) > 1)
{
$section = $parts[1];
}

// Try to find the component helper.
$eName = str_replace('com_', '', $component);
$file = \JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $component . '/helpers/' . $eName . '.php');
$component = Factory::getApplication()->bootComponent($parts[0]);

if (file_exists($file))
if ($component instanceof CategoriesServiceInterface)
{
$prefix = ucfirst($eName);
$cName = $prefix . 'Helper';

\JLoader::register($cName, $file);

if (class_exists($cName) && is_callable(array($cName, 'countItems')))
{
$cName::countItems($items, $section);
}
$component->countItems($items, $section);
}
}
}
21 changes: 0 additions & 21 deletions administrator/components/com_content/Dispatcher/Dispatcher.php

This file was deleted.

133 changes: 133 additions & 0 deletions administrator/components/com_content/Extension/ContentComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_content
*
* @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Content\Administrator\Extension;

defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Association\AssociationServiceTrait;
use Joomla\CMS\Association\AssociationServiceInterface;
use Joomla\CMS\Categories\CategoriesServiceInterface;
use Joomla\CMS\Categories\CategoriesServiceTrait;
use Joomla\CMS\Extension\BootableExtensionInterface;
use Joomla\CMS\Extension\Component;
use Joomla\CMS\Fields\FieldsServiceInterface;
use Joomla\CMS\HTML\HTMLRegistryAwareTrait;
use Joomla\CMS\MVC\Factory\MVCFactoryServiceTrait;
use Joomla\CMS\MVC\Factory\MVCFactoryServiceInterface;
use Joomla\Component\Content\Administrator\Service\HTML\AdministratorService;
use Joomla\Component\Content\Administrator\Service\HTML\Icon;
use Psr\Container\ContainerInterface;

/**
* Component class for com_content
*
* @since __DEPLOY_VERSION__
*/
class ContentComponent extends Component implements
BootableExtensionInterface, MVCFactoryServiceInterface, CategoriesServiceInterface, FieldsServiceInterface, AssociationServiceInterface
{
use MVCFactoryServiceTrait;
use CategoriesServiceTrait;
use AssociationServiceTrait;
use HTMLRegistryAwareTrait;

/**
* 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 __DEPLOY_VERSION__
*/
public function boot(ContainerInterface $container)
{
$this->getRegistry()->register('contentadministrator', new AdministratorService);
$this->getRegistry()->register('contenticon', new Icon($container->get(SiteApplication::class)));

// The layout joomla.content.icons does need a general icon service
$this->getRegistry()->register('icon', $this->getRegistry()->getService('contenticon'));
}

/**
* Returns a valid section for the given section. If it is not valid then null
* is returned.
*
* @param string $section The section to get the mapping for
* @param object $item The item
*
* @return string|null The new section
*
* @since __DEPLOY_VERSION__
*/
public function validateSection($section, $item = null)
{
if (\JFactory::getApplication()->isClient('site'))
{
// On the front end we need to map some sections
switch ($section)
{
// Editing an article
case 'form':

// Category list view
case 'featured':
case 'category':
$section = 'article';
}
}

if ($section != 'article')
{
// We don't know other sections
return null;
}

return $section;
}

/**
* Returns valid contexts
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public function getContexts(): array
{
\JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR);

$contexts = array(
'com_content.article' => \JText::_('COM_CONTENT'),
'com_content.categories' => \JText::_('JCATEGORY')
);

return $contexts;
}

/**
* Returns the table for the count items functions for the given section.
*
* @param string $section The section
*
* @return string|null
*
* @since __DEPLOY_VERSION__
*/
protected function getTableNameForSection(string $section = null)
{
return '#__content';
}
}

0 comments on commit 80ed169

Please sign in to comment.