Skip to content

Commit

Permalink
Change com_templates to services
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed May 29, 2018
1 parent 21bb801 commit 47ae523
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_templates
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Templates\Administrator\Extension;

defined('JPATH_PLATFORM') or die;

use Joomla\CMS\Extension\BootableExtensionInterface;
use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\HTML\HTMLRegistryAwareTrait;
use Joomla\Component\Templates\Administrator\Service\HTML\Templates;
use Psr\Container\ContainerInterface;

/**
* Component class for com_templates
*
* @since 4.0.0
*/
class TemplatesComponent extends MVCComponent implements BootableExtensionInterface
{
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 4.0.0
*/
public function boot(ContainerInterface $container)
{
$this->getRegistry()->register('templates', new Templates);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Component\Templates\Administrator\Service\HTML;

defined('_JEXEC') or die;

use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;

/**
* JHtml helper class.
* Html helper class.
*
* @since 1.6
*/
class JHtmlTemplates
class Templates
{
/**
* Display the thumb for the template.
Expand All @@ -28,7 +33,7 @@ class JHtmlTemplates
*
* @since 1.6
*/
public static function thumb($template, $clientId = 0)
public function thumb($template, $clientId = 0)
{
$client = ApplicationHelper::getClientInfo($clientId);
$basePath = $client->path . '/templates/' . $template;
Expand All @@ -40,12 +45,12 @@ public static function thumb($template, $clientId = 0)
{
$clientPath = ($clientId == 0) ? '' : 'administrator/';
$thumb = $clientPath . 'templates/' . $template . '/template_thumbnail.png';
$html = JHtml::_('image', $thumb, JText::_('COM_TEMPLATES_PREVIEW'));
$html = HTMLHelper::_('image', $thumb, Text::_('COM_TEMPLATES_PREVIEW'));

if (file_exists($preview))
{
$html = '<a href="#' . $template . '-Modal" role="button" class="thumbnail float-left hasTooltip" data-toggle="modal" title="' .
JHtml::_('tooltipText', 'COM_TEMPLATES_CLICK_TO_ENLARGE') . '">' . $html . '</a>';
HTMLHelper::_('tooltipText', 'COM_TEMPLATES_CLICK_TO_ENLARGE') . '">' . $html . '</a>';
}
}

Expand All @@ -62,35 +67,32 @@ public static function thumb($template, $clientId = 0)
*
* @since 3.4
*/
public static function thumbModal($template, $clientId = 0)
public function thumbModal($template, $clientId = 0)
{
$client = ApplicationHelper::getClientInfo($clientId);
$basePath = $client->path . '/templates/' . $template;
$baseUrl = ($clientId == 0) ? JUri::root(true) : JUri::root(true) . '/administrator';
$baseUrl = ($clientId == 0) ? Uri::root(true) : Uri::root(true) . '/administrator';
$thumb = $basePath . '/template_thumbnail.png';
$preview = $basePath . '/template_preview.png';
$html = '';

if (file_exists($thumb))
if (file_exists($thumb) && file_exists($preview))
{
if (file_exists($preview))
{
$preview = $baseUrl . '/templates/' . $template . '/template_preview.png';
$footer = '<button type="button" class="btn btn-secondary" data-dismiss="modal" aria-hidden="true">'
. JText::_('JTOOLBAR_CLOSE') . '</button>';
$preview = $baseUrl . '/templates/' . $template . '/template_preview.png';
$footer = '<button type="button" class="btn btn-secondary" data-dismiss="modal" aria-hidden="true">'
. Text::_('JTOOLBAR_CLOSE') . '</button>';

$html .= JHtml::_(
'bootstrap.renderModal',
$template . '-Modal',
array(
'title' => JText::_('COM_TEMPLATES_BUTTON_PREVIEW'),
'height' => '500px',
'width' => '800px',
'footer' => $footer,
),
$body = '<div><img src="' . $preview . '" style="max-width:100%" alt="' . $template . '"></div>'
);
}
$html .= HTMLHelper::_(
'bootstrap.renderModal',
$template . '-Modal',
array(
'title' => Text::_('COM_TEMPLATES_BUTTON_PREVIEW'),
'height' => '500px',
'width' => '800px',
'footer' => $footer,
),
$body = '<div><img src="' . $preview . '" style="max-width:100%" alt="' . $template . '"></div>'
);
}

return $html;
Expand Down
31 changes: 0 additions & 31 deletions administrator/components/com_templates/dispatcher.php

This file was deleted.

20 changes: 0 additions & 20 deletions administrator/components/com_templates/helpers/template.php

This file was deleted.

20 changes: 0 additions & 20 deletions administrator/components/com_templates/helpers/templates.php

This file was deleted.

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

defined('_JEXEC') or die;

use Joomla\CMS\Dispatcher\DispatcherFactoryInterface;
use Joomla\CMS\Extension\ComponentInterface;
use Joomla\CMS\Extension\MVCComponent;
use Joomla\CMS\Extension\Service\Provider\DispatcherFactory;
use Joomla\CMS\Extension\Service\Provider\MVCFactoryFactory;
use Joomla\CMS\MVC\Factory\MVCFactoryFactoryInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

/**
* The templates service provider.
*
* @since 4.0.0
*/
return new class implements ServiceProviderInterface
{
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.0.0
*/
public function register(Container $container)
{
$container->registerServiceProvider(new MVCFactoryFactory('\\Joomla\\Component\\Templates'));
$container->registerServiceProvider(new DispatcherFactory('\\Joomla\\Component\\Templates'));

$container->set(
ComponentInterface::class,
function (Container $container)
{
$component = new MVCComponent($container->get(DispatcherFactoryInterface::class));

$component->setMvcFactoryFactory($container->get(MVCFactoryFactoryInterface::class));

return $component;
}
);
}
};
3 changes: 3 additions & 0 deletions libraries/extensions.classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
JLoader::registerAlias('FieldsListPlugin', '\\Joomla\\Component\\Fields\\Administrator\\Plugin\\FieldsListPlugin', '4.0');

JLoader::registerAlias('TagsTableTag', '\\Joomla\\Component\\Tags\\Administrator\\Table\\TagTable', '4.0');

JLoader::registerAlias('TemplatesHelper', '\\Joomla\\Component\\Templates\\Administrator\\Helper\\TemplatesHelper', '5.0');
JLoader::registerAlias('TemplateHelper', '\\Joomla\\Component\\Templates\\Administrator\\Helper\\TemplateHelper', '5.0');

0 comments on commit 47ae523

Please sign in to comment.