JoomlaPolska / jezyk-J4

Język polski dla Joomla 4
GNU General Public License v2.0
3 stars 5 forks source link

[5.0][RFC] Move Toolbar singleton to HtmlDocument #398

Closed joomlapl-bot closed 5 months ago

joomlapl-bot commented 1 year ago

PR w związku ze zmianą oryginału https://github.com/joomla/joomla-cms/pull/41254 Poniżej zmiany w oryginale:

Click to expand the diff! ```diff diff --git a/administrator/components/com_finder/src/View/Indexer/HtmlView.php b/administrator/components/com_finder/src/View/Indexer/HtmlView.php index af1e7c5eafe6e..7dcd1ba819bc8 100644 --- a/administrator/components/com_finder/src/View/Indexer/HtmlView.php +++ b/administrator/components/com_finder/src/View/Indexer/HtmlView.php @@ -10,7 +10,6 @@ namespace Joomla\Component\Finder\Administrator\View\Indexer; -use Joomla\CMS\Factory; use Joomla\CMS\Form\Form; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; @@ -64,17 +63,14 @@ public function display($tpl = null) */ protected function addToolbar() { - $toolbar = Toolbar::getInstance('toolbar'); + /** @var Toolbar $toolbar */ + $toolbar = $this->getDocument()->getToolbar(); ToolbarHelper::title(Text::_('COM_FINDER_INDEXER_TOOLBAR_TITLE'), 'search-plus finder'); - $arrow = Factory::getLanguage()->isRtl() ? 'arrow-right' : 'arrow-left'; - - ToolbarHelper::link( - Route::_('index.php?option=com_finder&view=index'), - 'JTOOLBAR_BACK', - $arrow - ); + $toolbar->linkButton('back', 'JTOOLBAR_BACK') + ->icon('icon-arrow-' . ($this->getLanguage()->isRtl() ? 'right' : 'left')) + ->url(Route::_('index.php?option=com_finder&view=index')); $toolbar->standardButton('index', 'COM_FINDER_INDEX') ->icon('icon-play') diff --git a/administrator/components/com_finder/src/View/Item/HtmlView.php b/administrator/components/com_finder/src/View/Item/HtmlView.php index ef50034d3d5a3..70b4af4cd8077 100644 --- a/administrator/components/com_finder/src/View/Item/HtmlView.php +++ b/administrator/components/com_finder/src/View/Item/HtmlView.php @@ -12,6 +12,8 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Toolbar\Toolbar; use Joomla\CMS\Toolbar\ToolbarHelper; /** @@ -78,7 +80,13 @@ public function display($tpl = null) */ protected function addToolbar() { + /** @var Toolbar $toolbar */ + $toolbar = $this->getDocument()->getToolbar(); + ToolbarHelper::title(Text::_('COM_FINDER_INDEX_TOOLBAR_TITLE'), 'search-plus finder'); - ToolbarHelper::back('JTOOLBAR_BACK', 'index.php?option=com_finder&view=index'); + + $toolbar->linkButton('back', 'JTOOLBAR_BACK') + ->icon('icon-arrow-' . ($this->getLanguage()->isRtl() ? 'right' : 'left')) + ->url(Route::_('index.php?option=com_finder&view=index')); } } diff --git a/administrator/language/en-GB/mod_toolbar.ini b/administrator/language/en-GB/mod_toolbar.ini index 880c42614dad2..aec2f9d4d4a1a 100644 --- a/administrator/language/en-GB/mod_toolbar.ini +++ b/administrator/language/en-GB/mod_toolbar.ini @@ -4,4 +4,6 @@ ; Note : All ini files need to be saved as UTF-8 MOD_TOOLBAR="Toolbar" -MOD_TOOLBAR_XML_DESCRIPTION="This module shows the toolbar icons used to control actions throughout the Administrator area." \ No newline at end of file +MOD_TOOLBAR_FIELD_TOOLBAR_LABEL="Toolbar Identifier" +MOD_TOOLBAR_FIELD_TOOLBAR_DESCRIPTION="The default toolbar in the administrator is called 'toolbar', if you have an extension that generate own toolbars you can create an own module with it's toolbar identifier. The default toolbar should never be removed!" +MOD_TOOLBAR_XML_DESCRIPTION="This module shows the toolbar icons used to control actions throughout the Administrator area." diff --git a/administrator/modules/mod_toolbar/mod_toolbar.php b/administrator/modules/mod_toolbar/mod_toolbar.php index 9466a9efd76b3..4c1cb606e6f6a 100644 --- a/administrator/modules/mod_toolbar/mod_toolbar.php +++ b/administrator/modules/mod_toolbar/mod_toolbar.php @@ -10,9 +10,11 @@ defined('_JEXEC') or die; +use Joomla\CMS\Factory; use Joomla\CMS\Helper\ModuleHelper; -use Joomla\CMS\Toolbar\Toolbar; -$toolbar = Toolbar::getInstance('toolbar')->render(); +/** @var $params Joomla\Registry\Registry */ + +$toolbar = Factory::getApplication()->getDocument()->getToolbar($params->get('toolbar', 'toolbar'))->render(); require ModuleHelper::getLayoutPath('mod_toolbar', $params->get('layout', 'default')); diff --git a/administrator/modules/mod_toolbar/mod_toolbar.xml b/administrator/modules/mod_toolbar/mod_toolbar.xml index 41cb6c5c8e182..05ba439b0e4d9 100644 --- a/administrator/modules/mod_toolbar/mod_toolbar.xml +++ b/administrator/modules/mod_toolbar/mod_toolbar.xml @@ -20,6 +20,16 @@ +
+ +
+
toolbars[$toolbar])) { + if (!$create) { + return null; + } + + $this->toolbars[$toolbar] = CmsFactory::getContainer()->get(ToolbarFactoryInterface::class)->createToolbar($toolbar); + } + + return $this->toolbars[$toolbar]; + } + + /** + * Returns the toolbar array + * + * @return array + * + * @since __DEPLOY_VERSION__ + */ + public function getToolbars(): array + { + return $this->toolbars; + } + + /** + * Adds a new or replace an existing toolbar object + * + * @param string $name + * @param Toolbar $toolbar + * + * @return $this + * + * @since __DEPLOY_VERSION__ + */ + public function setToolbar(string $name, Toolbar $toolbar): self + { + $this->toolbars[$name] = $toolbar; + + return $this; + } + /** * Parse a document template * diff --git a/libraries/src/Toolbar/Toolbar.php b/libraries/src/Toolbar/Toolbar.php index b12497aa60f7b..fe5297bcfaef5 100644 --- a/libraries/src/Toolbar/Toolbar.php +++ b/libraries/src/Toolbar/Toolbar.php @@ -77,6 +77,10 @@ class Toolbar * * @var Toolbar[] * @since 2.5 + * + * @deprecated 5.0 will be removed in 7.0 + * Toolbars instances will be stored in the \Joomla\CMS\Document\HTMLDocument object + * Request the instance from Factory::getApplication()->getDocument()->getToolbar('name'); */ protected static $instances = []; @@ -141,11 +145,14 @@ public function __construct($name = 'toolbar', ToolbarFactoryInterface $factory */ public static function getInstance($name = 'toolbar') { + $toolbar = Factory::getApplication()->getDocument()->getToolbar($name); + + // TODO b/c remove with Joomla 7.0 or removed in 6.0 with this function if (empty(self::$instances[$name])) { - self::$instances[$name] = Factory::getContainer()->get(ToolbarFactoryInterface::class)->createToolbar($name); + self::$instances[$name] = $toolbar; } - return self::$instances[$name]; + return $toolbar; } /** diff --git a/libraries/src/Toolbar/ToolbarHelper.php b/libraries/src/Toolbar/ToolbarHelper.php index ea2fbe5867b82..e5a19fdf6df5e 100644 --- a/libraries/src/Toolbar/ToolbarHelper.php +++ b/libraries/src/Toolbar/ToolbarHelper.php @@ -52,7 +52,7 @@ public static function title($title, $icon = 'generic.png') $title .= ' - ' . Text::_('JADMINISTRATION'); } - Factory::getDocument()->setTitle($title); + $app->getDocument()->setTitle($title); } /** ```