Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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,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;
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;

/**
Expand Down Expand Up @@ -78,7 +79,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'));
}
}
62 changes: 62 additions & 0 deletions libraries/src/Document/HtmlDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarFactoryInterface;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Utility\Utility;
use Joomla\Registry\Registry;
Expand Down Expand Up @@ -121,6 +123,14 @@ class HtmlDocument extends Document implements CacheControllerFactoryAwareInterf
*/
private $html5 = true;

/**
* List of type \Joomla\CMS\Toolbar\Toolbar
*
* @var Toolbar[]
* @since __DEPLOY_VERSION__
*/
private $toolbars = [];

/**
* Class constructor
*
Expand Down Expand Up @@ -778,6 +788,58 @@ protected function _fetchTemplate($params = [])
return $this;
}

/**
* Returns a toolbar object or null
*
* @param string $toolbar
* @param boolean $create
*
* @return ?Toolbar
*
* @since __DEPLOY_VERSION__
*/
public function getToolbar(string $toolbar = 'toolbar', bool $create = true): ?Toolbar
{
if (empty($this->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
*
Expand Down
11 changes: 9 additions & 2 deletions libraries/src/Toolbar/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Toolbar/ToolbarHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function title($title, $icon = 'generic.png')
$title .= ' - ' . Text::_('JADMINISTRATION');
}

Factory::getDocument()->setTitle($title);
$app->getDocument()->setTitle($title);
}

/**
Expand Down