[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_menus/src/View/Menu/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_menus
   6   *
   7   * @copyright   (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Menus\Administrator\View\Menu;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Helper\ContentHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\MVC\View\GenericDataException;
  17  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  18  use Joomla\CMS\Object\CMSObject;
  19  use Joomla\CMS\Toolbar\ToolbarHelper;
  20  
  21  // phpcs:disable PSR1.Files.SideEffects
  22  \defined('_JEXEC') or die;
  23  // phpcs:enable PSR1.Files.SideEffects
  24  
  25  /**
  26   * The HTML Menus Menu Item View.
  27   *
  28   * @since  1.6
  29   */
  30  class HtmlView extends BaseHtmlView
  31  {
  32      /**
  33       * The Form object
  34       *
  35       * @var  \Joomla\CMS\Form\Form
  36       */
  37      protected $form;
  38  
  39      /**
  40       * The active item
  41       *
  42       * @var  object
  43       */
  44      protected $item;
  45  
  46      /**
  47       * The model state
  48       *
  49       * @var  CMSObject
  50       */
  51      protected $state;
  52  
  53      /**
  54       * The actions the user is authorised to perform
  55       *
  56       * @var  CMSObject
  57       */
  58      protected $canDo;
  59  
  60      /**
  61       * Display the view
  62       *
  63       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  64       *
  65       * @return  void
  66       *
  67       * @since   1.6
  68       */
  69      public function display($tpl = null)
  70      {
  71          $this->form  = $this->get('Form');
  72          $this->item  = $this->get('Item');
  73          $this->state = $this->get('State');
  74  
  75          $this->canDo = ContentHelper::getActions('com_menus', 'menu', $this->item->id);
  76  
  77          // Check for errors.
  78          if (count($errors = $this->get('Errors'))) {
  79              throw new GenericDataException(implode("\n", $errors), 500);
  80          }
  81  
  82          parent::display($tpl);
  83          $this->addToolbar();
  84      }
  85  
  86      /**
  87       * Add the page title and toolbar.
  88       *
  89       * @return  void
  90       *
  91       * @since   1.6
  92       */
  93      protected function addToolbar()
  94      {
  95          $input = Factory::getApplication()->input;
  96          $input->set('hidemainmenu', true);
  97  
  98          $isNew = ($this->item->id == 0);
  99  
 100          ToolbarHelper::title(Text::_($isNew ? 'COM_MENUS_VIEW_NEW_MENU_TITLE' : 'COM_MENUS_VIEW_EDIT_MENU_TITLE'), 'list menu');
 101  
 102          $toolbarButtons = [];
 103  
 104          // If a new item, can save the item.  Allow users with edit permissions to apply changes to prevent returning to grid.
 105          if ($isNew && $this->canDo->get('core.create')) {
 106              if ($this->canDo->get('core.edit')) {
 107                  ToolbarHelper::apply('menu.apply');
 108              }
 109  
 110              $toolbarButtons[] = ['save', 'menu.save'];
 111          }
 112  
 113          // If user can edit, can save the item.
 114          if (!$isNew && $this->canDo->get('core.edit')) {
 115              ToolbarHelper::apply('menu.apply');
 116  
 117              $toolbarButtons[] = ['save', 'menu.save'];
 118          }
 119  
 120          // If the user can create new items, allow them to see Save & New
 121          if ($this->canDo->get('core.create')) {
 122              $toolbarButtons[] = ['save2new', 'menu.save2new'];
 123          }
 124  
 125          ToolbarHelper::saveGroup(
 126              $toolbarButtons,
 127              'btn-success'
 128          );
 129  
 130          if ($isNew) {
 131              ToolbarHelper::cancel('menu.cancel');
 132          } else {
 133              ToolbarHelper::cancel('menu.cancel', 'JTOOLBAR_CLOSE');
 134          }
 135  
 136          ToolbarHelper::divider();
 137          ToolbarHelper::help('Menus:_Edit');
 138      }
 139  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer