Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] Component services in Component class #20217

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1a0e3ec
ComponentHelper interface
laoneo Mar 5, 2018
87808ae
Merge branch '4.0-dev' into j4/service/helper
laoneo Mar 6, 2018
2ce8708
CS
laoneo Mar 6, 2018
a88492a
Merge remote-tracking branch 'origin/j4/service/helper' into j4/servi…
laoneo Mar 6, 2018
b073827
Merge remote-tracking branch 'remotes/upstream/4.0-dev' into j4/servi…
laoneo Mar 7, 2018
ad0bc93
Merge branch '4.0-dev' into j4/service/helper
laoneo Mar 9, 2018
1eda0c1
Merge remote-tracking branch 'remotes/upstream/4.0-dev' into j4/servi…
laoneo Mar 10, 2018
668f26b
Merge branch '4.0-dev' into j4/service/helper
laoneo Mar 14, 2018
da08aee
Remove the need for empty dispatcher classes
laoneo Mar 14, 2018
5a16976
Merge branch '4.0-dev' into j4/service/helper
laoneo Mar 22, 2018
c215221
Merge branch '4.0-dev' into j4/service/helper
laoneo Mar 23, 2018
735b921
Merge remote-tracking branch 'remotes/upstream/4.0-dev' into j4/dispa…
laoneo Mar 25, 2018
3e0ad82
Merge branch '4.0-dev' into j4/service/helper
laoneo Mar 26, 2018
14a7da9
Merge branch '4.0-dev' into j4/dispatcher/empty
laoneo Mar 26, 2018
ba065a5
Support multiple dispatchers
laoneo Mar 26, 2018
044a7cb
Merge branch '4.0-dev' into j4/dispatcher/empty
laoneo Apr 4, 2018
0e58ae0
Merge branch '4.0-dev' into j4/dispatcher/empty
zero-24 Apr 7, 2018
7e92896
Get the option form the input
laoneo Apr 8, 2018
6bb6124
Move extension container services to service providers
laoneo Apr 8, 2018
991532c
Merge branch '4.0-dev' into j4/extension/service/providers
laoneo Apr 8, 2018
ef62da4
Merge branch '4.0-dev' into j4/service/helper
laoneo Apr 9, 2018
22a25b2
Merge branch '4.0-dev' into j4/extension/service/providers
laoneo Apr 9, 2018
acf5670
Merge remote-tracking branch 'remotes/upstream/4.0-dev' into j4/servi…
laoneo Apr 10, 2018
2cf8a9d
add helper provider interface
laoneo Apr 10, 2018
68ca58a
CS
laoneo Apr 10, 2018
699e560
Let the component class define which services it provides
laoneo Apr 16, 2018
aeb0399
Move filesystem path lookup back into the helper class
laoneo Apr 16, 2018
563b0b8
Use the com_content component service provider
laoneo Apr 21, 2018
d9c48b1
Merge branch '4.0-dev' into j4/service/assoc
laoneo Apr 21, 2018
cb2862b
Inject the service in the component specific service provider
laoneo Apr 21, 2018
526808f
Merge remote-tracking branch 'origin/j4/service/assoc' into j4/servic…
laoneo Apr 21, 2018
772afb9
Merge branch 'j4/dispatcher/empty' into j4/extension/content/service/…
laoneo Apr 22, 2018
2a2812c
Merge remote-tracking branch 'origin/j4/extension/service/providers' …
laoneo Apr 22, 2018
c69d921
Bootable interface
laoneo Apr 22, 2018
70a9354
HTML registry aware interface
laoneo Apr 22, 2018
45c13f1
MVC factory aware trait
laoneo Apr 22, 2018
9478379
Categories
laoneo Apr 22, 2018
0821232
Categories service
laoneo Apr 22, 2018
0108369
cleanup providers
laoneo Apr 22, 2018
484cc2f
Cleanup
laoneo Apr 23, 2018
3a6be33
Merge branch 'j4/service/helper' into j4/extension/content/service/lo…
laoneo Apr 23, 2018
2493468
Categories and fields helper
laoneo Apr 23, 2018
2177e22
Boot function gets a PSR container
laoneo Apr 23, 2018
dc383c9
Fallback to input option
laoneo Apr 23, 2018
ef1b45f
Merge branch 'j4/dispatcher/empty' into j4/extension/content/service/…
laoneo Apr 23, 2018
420e6be
Revert no dispatcher code as it is in another pr
laoneo Apr 23, 2018
a8f0abc
CS
laoneo Apr 23, 2018
f077555
CS
laoneo Apr 23, 2018
67ed463
CS
laoneo Apr 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -96,7 +98,7 @@ public static function getExtensionHelper($extensionName)
*
* @return \Joomla\CMS\Table\Table|null
*
* @since 3.7.00
* @since 3.7.0
*/
public static function getItem($extensionName, $typeName, $itemId)
{
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);
}
}
}
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';
}
}
Loading