- md5
- 616fcb00c500db1e3db8e1ea6b943288
- sha1
- b1898d81c3872c7104ecdb17dc091b1b77cbfbf5
- sha256
- fefb75e6a0e5ff9eb42ac57b243430493616fa879db5237ac2809f4089c98dd9
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
<?php
/**
* @package Joomla.Administrator
* @subpackage com_modules
*
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Modules\Administrator\View\Module;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Modules\Administrator\Model\ModuleModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* View to edit a module.
*
* @since 1.6
*/
class HtmlView extends BaseHtmlView
{
/**
* The Form object
*
* @var \Joomla\CMS\Form\Form
*/
protected $form;
/**
* The active item
*
* @var object
*/
protected $item;
/**
* The model state
*
* @var \Joomla\Registry\Registry
*/
protected $state;
/**
* The actions the user is authorised to perform
*
* @var \Joomla\Registry\Registry
*
* @since 4.0.0
*/
protected $canDo;
/**
* Array of fieldsets not to display
*
* @var string[]
*
* @since 5.2.0
*/
public $ignore_fieldsets = [];
/**
* Display the view
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*/
public function display($tpl = null)
{
/** @var ModuleModel $model */
$model = $this->getModel();
$model->setUseExceptions(true);
$this->state = $model->getState();
// Have to stop it earlier, because on cancel task for a new module we do not have an ID, and Model doing redirect on getItem()
if ($this->getLayout() === 'modalreturn' && !$this->state->get('module.id')) {
parent::display($tpl);
return;
}
$this->form = $model->getForm();
$this->item = $model->getItem();
$this->canDo = ContentHelper::getActions('com_modules', 'module', $this->item->id);
if ($this->getLayout() === 'modalreturn') {
parent::display($tpl);
return;
}
$input = Factory::getApplication()->getInput();
$forcedLanguage = $input->get('forcedLanguage', '', 'cmd');
// If we are forcing a language in modal (used for associations).
if ($this->getLayout() === 'modal' && $forcedLanguage) {
// Set the language field to the forcedLanguage and disable changing it.
$this->form->setValue('language', null, $forcedLanguage);
$this->form->setFieldAttribute('language', 'readonly', 'true');
// Only allow to select categories with All language or with the forced language.
$this->form->setFieldAttribute('parent_id', 'language', '*,' . $forcedLanguage);
}
// Add form control fields
$this->form
->addControlField('task')
->addControlField('return', Factory::getApplication()->getInput()->getBase64('return', ''));
if ($this->getLayout() !== 'modal') {
$this->addToolbar();
} else {
$this->addModalToolbar();
}
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
Factory::getApplication()->getInput()->set('hidemainmenu', true);
$user = $this->getCurrentUser();
$isNew = ($this->item->id == 0);
$checkedOut = !(\is_null($this->item->checked_out) || $this->item->checked_out == $user->id);
$canDo = $this->canDo;
$toolbar = $this->getDocument()->getToolbar();
ToolbarHelper::title(Text::sprintf('COM_MODULES_MANAGER_MODULE', Text::_($this->item->module)), 'cube module');
// For new records, check the create permission.
if ($isNew && $canDo->get('core.create')) {
$toolbar->apply('module.apply');
$saveGroup = $toolbar->dropdownButton('save-group');
$saveGroup->configure(
function (Toolbar $childBar) {
$childBar->save('module.save');
$childBar->save2new('module.save2new');
}
);
$toolbar->cancel('module.cancel', 'JTOOLBAR_CANCEL');
} else {
// Can't save the record if it's checked out.
if (!$checkedOut && $canDo->get('core.edit')) {
$toolbar->apply('module.apply');
}
$saveGroup = $toolbar->dropdownButton('save-group');
$saveGroup->configure(
function (Toolbar $childBar) use ($checkedOut, $canDo) {
// Can't save the record if it's checked out. Since it's an existing record, check the edit permission.
if (!$checkedOut && $canDo->get('core.edit')) {
$childBar->save('module.save');
// We can save this record, but check the create permission to see if we can return to make a new one.
if ($canDo->get('core.create')) {
$childBar->save2new('module.save2new');
}
}
// If checked out, we can still save
if ($canDo->get('core.create')) {
$childBar->save2copy('module.save2copy');
}
}
);
$toolbar->cancel('module.cancel');
if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->get('params')->get('save_history', 1) && $canDo->get('core.edit')) {
$toolbar->versions('com_modules.module', $this->item->id);
}
if (Associations::isEnabled() && ComponentHelper::isEnabled('com_associations') && $this->item->client_id === 0) {
$toolbar->standardButton('associations', 'JTOOLBAR_ASSOCIATIONS', 'module.editAssociations')
->icon('icon-contract')
->listCheck(false);
}
}
// Get the help information for the menu item.
$lang = $this->getLanguage();
/** @var ModuleModel $model */
$model = $this->getModel();
$help = $model->getHelp();
if ($lang->hasKey($help->url)) {
$debug = $lang->setDebug(false);
$url = Text::_($help->url);
$lang->setDebug($debug);
} else {
$url = null;
}
$toolbar->inlinehelp();
$toolbar->help($help->key, false, $url);
}
/**
* Add the modal toolbar.
*
* @return void
*
* @since 5.1.0
*
* @throws \Exception
*/
protected function addModalToolbar()
{
$isNew = ($this->item->id == 0);
$toolbar = $this->getDocument()->getToolbar();
$canDo = $this->canDo;
ToolbarHelper::title(Text::sprintf('COM_MODULES_MANAGER_MODULE', Text::_($this->item->module)), 'cube module');
$canCreate = $isNew && $canDo->get('core.create');
$canEdit = $canDo->get('core.edit');
// For new records, check the create permission.
if ($canCreate || $canEdit) {
$toolbar->apply('module.apply');
$toolbar->save('module.save');
}
$toolbar->cancel('module.cancel');
$toolbar->inlinehelp();
}
}
The same content is in 7 releases, Joomla 6.1.0-beta1 to 6.1.0. See them all, or every version of this file.