[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/editors-xtd/article/ -> article.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  Editors-xtd.article
   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   * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
  11   */
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\CMS\Object\CMSObject;
  16  use Joomla\CMS\Plugin\CMSPlugin;
  17  use Joomla\CMS\Session\Session;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('_JEXEC') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * Editor Article button
  25   *
  26   * @since  1.5
  27   */
  28  class PlgButtonArticle extends CMSPlugin
  29  {
  30      /**
  31       * Load the language file on instantiation.
  32       *
  33       * @var    boolean
  34       * @since  3.1
  35       */
  36      protected $autoloadLanguage = true;
  37  
  38      /**
  39       * Display the button
  40       *
  41       * @param   string  $name  The name of the button to add
  42       *
  43       * @return  CMSObject|void  The button options as CMSObject, void if ACL check fails.
  44       *
  45       * @since   1.5
  46       */
  47      public function onDisplay($name)
  48      {
  49          $user  = Factory::getUser();
  50  
  51          // Can create in any category (component permission) or at least in one category
  52          $canCreateRecords = $user->authorise('core.create', 'com_content')
  53              || count($user->getAuthorisedCategories('com_content', 'core.create')) > 0;
  54  
  55          // Instead of checking edit on all records, we can use **same** check as the form editing view
  56          $values = (array) Factory::getApplication()->getUserState('com_content.edit.article.id');
  57          $isEditingRecords = count($values);
  58  
  59          // This ACL check is probably a double-check (form view already performed checks)
  60          $hasAccess = $canCreateRecords || $isEditingRecords;
  61          if (!$hasAccess) {
  62              return;
  63          }
  64  
  65          $link = 'index.php?option=com_content&amp;view=articles&amp;layout=modal&amp;tmpl=component&amp;'
  66              . Session::getFormToken() . '=1&amp;editor=' . $name;
  67  
  68          $button = new CMSObject();
  69          $button->modal   = true;
  70          $button->link    = $link;
  71          $button->text    = Text::_('PLG_ARTICLE_BUTTON_ARTICLE');
  72          $button->name    = $this->_type . '_' . $this->_name;
  73          $button->icon    = 'file-add';
  74          $button->iconSVG = '<svg viewBox="0 0 32 32" width="24" height="24"><path d="M28 24v-4h-4v4h-4v4h4v4h4v-4h4v-4zM2 2h18v6h6v10h2v-10l-8-'
  75                                  . '8h-20v32h18v-2h-16z"></path></svg>';
  76          $button->options = [
  77              'height'     => '300px',
  78              'width'      => '800px',
  79              'bodyHeight' => '70',
  80              'modalWidth' => '80',
  81          ];
  82  
  83          return $button;
  84      }
  85  }


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