[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  com_contact
   6   *
   7   * @copyright   (C) 2020 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\Site\View\Form;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Helper\TagsHelper;
  15  use Joomla\CMS\Language\Multilanguage;
  16  use Joomla\CMS\Language\Text;
  17  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  18  use Joomla\Component\Contact\Administrator\Helper\ContactHelper;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * HTML Contact View class for the Contact component
  26   *
  27   * @since  4.0.0
  28   */
  29  class HtmlView extends BaseHtmlView
  30  {
  31      /**
  32       * @var    \Joomla\CMS\Form\Form
  33       * @since  4.0.0
  34       */
  35      protected $form;
  36  
  37      /**
  38       * @var    object
  39       * @since  4.0.0
  40       */
  41      protected $item;
  42  
  43      /**
  44       * @var    string
  45       * @since  4.0.0
  46       */
  47      protected $return_page;
  48  
  49      /**
  50       * @var    string
  51       * @since  4.0.0
  52       */
  53      protected $pageclass_sfx;
  54  
  55      /**
  56       * @var    \Joomla\Registry\Registry
  57       * @since  4.0.0
  58       */
  59      protected $state;
  60  
  61      /**
  62       * @var    \Joomla\Registry\Registry
  63       * @since  4.0.0
  64       */
  65      protected $params;
  66  
  67      /**
  68       * Execute and display a template script.
  69       *
  70       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  71       *
  72       * @return  void|boolean
  73       *
  74       * @throws \Exception
  75       * @since  4.0.0
  76       */
  77      public function display($tpl = null)
  78      {
  79          $user = $this->getCurrentUser();
  80          $app  = Factory::getApplication();
  81  
  82          // Get model data.
  83          $this->state       = $this->get('State');
  84          $this->item        = $this->get('Item');
  85          $this->form        = $this->get('Form');
  86          $this->return_page = $this->get('ReturnPage');
  87  
  88          if (empty($this->item->id)) {
  89              $authorised = $user->authorise('core.create', 'com_contact') || count($user->getAuthorisedCategories('com_contact', 'core.create'));
  90          } else {
  91              // Since we don't track these assets at the item level, use the category id.
  92              $canDo      = ContactHelper::getActions('com_contact', 'category', $this->item->catid);
  93              $authorised = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by === $user->id);
  94          }
  95  
  96          if ($authorised !== true) {
  97              $app->enqueueMessage(Text::_('JERROR_ALERTNOAUTHOR'), 'error');
  98              $app->setHeader('status', 403, true);
  99  
 100              return false;
 101          }
 102  
 103          $this->item->tags = new TagsHelper();
 104  
 105          if (!empty($this->item->id)) {
 106              $this->item->tags->getItemTags('com_contact.contact', $this->item->id);
 107          }
 108  
 109          // Check for errors.
 110          if (count($errors = $this->get('Errors'))) {
 111              $app->enqueueMessage(implode("\n", $errors), 'error');
 112  
 113              return false;
 114          }
 115  
 116          // Create a shortcut to the parameters.
 117          $this->params = $this->state->params;
 118  
 119          // Escape strings for HTML output
 120          $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx', ''));
 121  
 122          // Override global params with contact specific params
 123          $this->params->merge($this->item->params);
 124  
 125          // Propose current language as default when creating new contact
 126          if (empty($this->item->id) && Multilanguage::isEnabled()) {
 127              $lang = Factory::getLanguage()->getTag();
 128              $this->form->setFieldAttribute('language', 'default', $lang);
 129          }
 130  
 131          $this->_prepareDocument();
 132  
 133          parent::display($tpl);
 134      }
 135  
 136      /**
 137       * Prepares the document
 138       *
 139       * @return  void
 140       *
 141       * @throws \Exception
 142       *
 143       * @since  4.0.0
 144       */
 145      protected function _prepareDocument()
 146      {
 147          $app = Factory::getApplication();
 148  
 149          // Because the application sets a default page title,
 150          // we need to get it from the menu item itself
 151          $menu = $app->getMenu()->getActive();
 152  
 153          if ($menu) {
 154              $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
 155          } else {
 156              $this->params->def('page_heading', Text::_('COM_CONTACT_FORM_EDIT_CONTACT'));
 157          }
 158  
 159          $title = $this->params->def('page_title', Text::_('COM_CONTACT_FORM_EDIT_CONTACT'));
 160  
 161          $this->setDocumentTitle($title);
 162  
 163          $pathway = $app->getPathWay();
 164          $pathway->addItem($title, '');
 165  
 166          if ($this->params->get('menu-meta_description')) {
 167              $this->document->setDescription($this->params->get('menu-meta_description'));
 168          }
 169  
 170          if ($this->params->get('menu-meta_keywords')) {
 171              $this->document->setMetaData('keywords', $this->params->get('menu-meta_keywords'));
 172          }
 173  
 174          if ($this->params->get('robots')) {
 175              $this->document->setMetaData('robots', $this->params->get('robots'));
 176          }
 177      }
 178  }


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