[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_contact/src/View/Contact/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_contact
   6   *
   7   * @copyright   (C) 2008 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\Contact\Administrator\View\Contact;
  12  
  13  use Joomla\CMS\Component\ComponentHelper;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\Helper\ContentHelper;
  16  use Joomla\CMS\Language\Associations;
  17  use Joomla\CMS\Language\Text;
  18  use Joomla\CMS\MVC\View\GenericDataException;
  19  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  20  use Joomla\CMS\Toolbar\Toolbar;
  21  use Joomla\CMS\Toolbar\ToolbarHelper;
  22  
  23  // phpcs:disable PSR1.Files.SideEffects
  24  \defined('_JEXEC') or die;
  25  // phpcs:enable PSR1.Files.SideEffects
  26  
  27  /**
  28   * View to edit a contact.
  29   *
  30   * @since  1.6
  31   */
  32  class HtmlView extends BaseHtmlView
  33  {
  34      /**
  35       * The Form object
  36       *
  37       * @var  \Joomla\CMS\Form\Form
  38       */
  39      protected $form;
  40  
  41      /**
  42       * The active item
  43       *
  44       * @var  object
  45       */
  46      protected $item;
  47  
  48      /**
  49       * The model state
  50       *
  51       * @var  \Joomla\CMS\Object\CMSObject
  52       */
  53      protected $state;
  54  
  55      /**
  56       * Display the view.
  57       *
  58       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  59       *
  60       * @return  void
  61       */
  62      public function display($tpl = null)
  63      {
  64          // Initialise variables.
  65          $this->form  = $this->get('Form');
  66          $this->item  = $this->get('Item');
  67          $this->state = $this->get('State');
  68  
  69          // Check for errors.
  70          if (count($errors = $this->get('Errors'))) {
  71              throw new GenericDataException(implode("\n", $errors), 500);
  72          }
  73  
  74          // If we are forcing a language in modal (used for associations).
  75          if ($this->getLayout() === 'modal' && $forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
  76              // Set the language field to the forcedLanguage and disable changing it.
  77              $this->form->setValue('language', null, $forcedLanguage);
  78              $this->form->setFieldAttribute('language', 'readonly', 'true');
  79  
  80              // Only allow to select categories with All language or with the forced language.
  81              $this->form->setFieldAttribute('catid', 'language', '*,' . $forcedLanguage);
  82  
  83              // Only allow to select tags with All language or with the forced language.
  84              $this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
  85          }
  86  
  87          $this->addToolbar();
  88  
  89          parent::display($tpl);
  90      }
  91  
  92      /**
  93       * Add the page title and toolbar.
  94       *
  95       * @return  void
  96       *
  97       * @since   1.6
  98       */
  99      protected function addToolbar()
 100      {
 101          Factory::getApplication()->input->set('hidemainmenu', true);
 102  
 103          $user       = $this->getCurrentUser();
 104          $userId     = $user->id;
 105          $isNew      = ($this->item->id == 0);
 106          $checkedOut = !(is_null($this->item->checked_out) || $this->item->checked_out == $userId);
 107  
 108          // Since we don't track these assets at the item level, use the category id.
 109          $canDo = ContentHelper::getActions('com_contact', 'category', $this->item->catid);
 110  
 111          $toolbar = Toolbar::getInstance();
 112  
 113          ToolbarHelper::title($isNew ? Text::_('COM_CONTACT_MANAGER_CONTACT_NEW') : Text::_('COM_CONTACT_MANAGER_CONTACT_EDIT'), 'address-book contact');
 114  
 115          // Build the actions for new and existing records.
 116          if ($isNew) {
 117              // For new records, check the create permission.
 118              if (count($user->getAuthorisedCategories('com_contact', 'core.create')) > 0) {
 119                  ToolbarHelper::apply('contact.apply');
 120  
 121                  $saveGroup = $toolbar->dropdownButton('save-group');
 122  
 123                  $saveGroup->configure(
 124                      function (Toolbar $childBar) use ($user) {
 125                          $childBar->save('contact.save');
 126  
 127                          if ($user->authorise('core.create', 'com_menus.menu')) {
 128                              $childBar->save('contact.save2menu', 'JTOOLBAR_SAVE_TO_MENU');
 129                          }
 130  
 131                          $childBar->save2new('contact.save2new');
 132                      }
 133                  );
 134              }
 135  
 136              ToolbarHelper::cancel('contact.cancel');
 137          } else {
 138              // Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
 139              $itemEditable = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId);
 140  
 141              // Can't save the record if it's checked out and editable
 142              if (!$checkedOut && $itemEditable) {
 143                  $toolbar->apply('contact.apply');
 144              }
 145  
 146              $saveGroup = $toolbar->dropdownButton('save-group');
 147  
 148              $saveGroup->configure(
 149                  function (Toolbar $childBar) use ($checkedOut, $itemEditable, $canDo, $user) {
 150                      // Can't save the record if it's checked out and editable
 151                      if (!$checkedOut && $itemEditable) {
 152                          $childBar->save('contact.save');
 153  
 154                          // We can save this record, but check the create permission to see if we can return to make a new one.
 155                          if ($canDo->get('core.create')) {
 156                              $childBar->save2new('contact.save2new');
 157                          }
 158                      }
 159  
 160                      // If checked out, we can still save2menu
 161                      if ($user->authorise('core.create', 'com_menus.menu')) {
 162                          $childBar->save('contact.save2menu', 'JTOOLBAR_SAVE_TO_MENU');
 163                      }
 164  
 165                      // If checked out, we can still save
 166                      if ($canDo->get('core.create')) {
 167                          $childBar->save2copy('contact.save2copy');
 168                      }
 169                  }
 170              );
 171  
 172              ToolbarHelper::cancel('contact.cancel', 'JTOOLBAR_CLOSE');
 173  
 174              if (ComponentHelper::isEnabled('com_contenthistory') && $this->state->params->get('save_history', 0) && $itemEditable) {
 175                  ToolbarHelper::versions('com_contact.contact', $this->item->id);
 176              }
 177  
 178              if (Associations::isEnabled() && ComponentHelper::isEnabled('com_associations')) {
 179                  ToolbarHelper::custom('contact.editAssociations', 'contract', '', 'JTOOLBAR_ASSOCIATIONS', false, false);
 180              }
 181          }
 182  
 183          ToolbarHelper::divider();
 184          ToolbarHelper::help('Contacts:_New_or_Edit');
 185      }
 186  }


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