[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_fields/src/View/Field/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_fields
   6   *
   7   * @copyright   (C) 2016 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\Fields\Administrator\View\Field;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Filesystem\Path;
  15  use Joomla\CMS\Helper\ContentHelper;
  16  use Joomla\CMS\Language\Text;
  17  use Joomla\CMS\MVC\View\GenericDataException;
  18  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  19  use Joomla\CMS\Object\CMSObject;
  20  use Joomla\CMS\Toolbar\ToolbarHelper;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('_JEXEC') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * Field View
  28   *
  29   * @since  3.7.0
  30   */
  31  class HtmlView extends BaseHtmlView
  32  {
  33      /**
  34       * @var     \Joomla\CMS\Form\Form
  35       *
  36       * @since   3.7.0
  37       */
  38      protected $form;
  39  
  40      /**
  41       * @var     CMSObject
  42       *
  43       * @since   3.7.0
  44       */
  45      protected $item;
  46  
  47      /**
  48       * @var     CMSObject
  49       *
  50       * @since   3.7.0
  51       */
  52      protected $state;
  53  
  54      /**
  55       * Execute and display a template script.
  56       *
  57       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  58       *
  59       * @return  void
  60       *
  61       * @see     HtmlView::loadTemplate()
  62       *
  63       * @since   3.7.0
  64       */
  65      public function display($tpl = null)
  66      {
  67          $this->form  = $this->get('Form');
  68          $this->item  = $this->get('Item');
  69          $this->state = $this->get('State');
  70  
  71          $this->canDo = ContentHelper::getActions($this->state->get('field.component'), 'field', $this->item->id);
  72  
  73          // Check for errors.
  74          if (count($errors = $this->get('Errors'))) {
  75              throw new GenericDataException(implode("\n", $errors), 500);
  76          }
  77  
  78          Factory::getApplication()->input->set('hidemainmenu', true);
  79  
  80          $this->addToolbar();
  81  
  82          parent::display($tpl);
  83      }
  84  
  85      /**
  86       * Adds the toolbar.
  87       *
  88       * @return  void
  89       *
  90       * @since   3.7.0
  91       */
  92      protected function addToolbar()
  93      {
  94          $component = $this->state->get('field.component');
  95          $section   = $this->state->get('field.section');
  96          $userId    = $this->getCurrentUser()->get('id');
  97          $canDo     = $this->canDo;
  98  
  99          $isNew      = ($this->item->id == 0);
 100          $checkedOut = !(is_null($this->item->checked_out) || $this->item->checked_out == $userId);
 101  
 102          // Avoid nonsense situation.
 103          if ($component == 'com_fields') {
 104              return;
 105          }
 106  
 107          // Load component language file
 108          $lang = Factory::getLanguage();
 109          $lang->load($component, JPATH_ADMINISTRATOR)
 110          || $lang->load($component, Path::clean(JPATH_ADMINISTRATOR . '/components/' . $component));
 111  
 112          $title = Text::sprintf('COM_FIELDS_VIEW_FIELD_' . ($isNew ? 'ADD' : 'EDIT') . '_TITLE', Text::_(strtoupper($component)));
 113  
 114          // Prepare the toolbar.
 115          ToolbarHelper::title(
 116              $title,
 117              'puzzle field-' . ($isNew ? 'add' : 'edit') . ' ' . substr($component, 4) . ($section ? "-$section" : '') . '-field-' .
 118              ($isNew ? 'add' : 'edit')
 119          );
 120  
 121          // For new records, check the create permission.
 122          if ($isNew) {
 123              ToolbarHelper::apply('field.apply');
 124  
 125              ToolbarHelper::saveGroup(
 126                  [
 127                      ['save', 'field.save'],
 128                      ['save2new', 'field.save2new']
 129                  ],
 130                  'btn-success'
 131              );
 132  
 133              ToolbarHelper::cancel('field.cancel');
 134          } else {
 135              // Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
 136              $itemEditable = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId);
 137  
 138              $toolbarButtons = [];
 139  
 140              // Can't save the record if it's checked out and editable
 141              if (!$checkedOut && $itemEditable) {
 142                  ToolbarHelper::apply('field.apply');
 143  
 144                  $toolbarButtons[] = ['save', 'field.save'];
 145  
 146                  // We can save this record, but check the create permission to see if we can return to make a new one.
 147                  if ($canDo->get('core.create')) {
 148                      $toolbarButtons[] = ['save2new', 'field.save2new'];
 149                  }
 150              }
 151  
 152              // If an existing item, can save to a copy.
 153              if ($canDo->get('core.create')) {
 154                  $toolbarButtons[] = ['save2copy', 'field.save2copy'];
 155              }
 156  
 157              ToolbarHelper::saveGroup(
 158                  $toolbarButtons,
 159                  'btn-success'
 160              );
 161  
 162              ToolbarHelper::cancel('field.cancel', 'JTOOLBAR_CLOSE');
 163          }
 164  
 165          ToolbarHelper::help('Component:_New_or_Edit_Field');
 166      }
 167  }


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