[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_workflow/src/View/Workflow/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_workflow
   6   *
   7   * @copyright   (C) 2018 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\Workflow\Administrator\View\Workflow;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\CMS\MVC\View\GenericDataException;
  16  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  17  use Joomla\CMS\Toolbar\ToolbarHelper;
  18  use Joomla\Component\Workflow\Administrator\Helper\WorkflowHelper;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * View class to add or edit a workflow
  26   *
  27   * @since  4.0.0
  28   */
  29  class HtmlView extends BaseHtmlView
  30  {
  31      /**
  32       * The model state
  33       *
  34       * @var    object
  35       * @since  4.0.0
  36       */
  37      protected $state;
  38  
  39      /**
  40       * The Form object
  41       *
  42       * @var  \Joomla\CMS\Form\Form
  43       */
  44      protected $form;
  45  
  46      /**
  47       * The active item
  48       *
  49       * @var  object
  50       */
  51      protected $item;
  52  
  53      /**
  54       * The ID of current workflow
  55       *
  56       * @var    integer
  57       * @since  4.0.0
  58       */
  59      protected $workflowID;
  60  
  61      /**
  62       * The name of current extension
  63       *
  64       * @var    string
  65       * @since  4.0.0
  66       */
  67      protected $extension;
  68  
  69      /**
  70       * The section of the current extension
  71       *
  72       * @var    string
  73       * @since  4.0.0
  74       */
  75      protected $section;
  76  
  77      /**
  78       * Display item view
  79       *
  80       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  81       *
  82       * @return  void
  83       *
  84       * @since  4.0.0
  85       */
  86      public function display($tpl = null)
  87      {
  88          // Get the Data
  89          $this->state      = $this->get('State');
  90          $this->form       = $this->get('Form');
  91          $this->item       = $this->get('Item');
  92  
  93          // Check for errors.
  94          if (count($errors = $this->get('Errors'))) {
  95              throw new GenericDataException(implode("\n", $errors), 500);
  96          }
  97  
  98          $extension = $this->state->get('filter.extension');
  99  
 100          $parts = explode('.', $extension);
 101  
 102          $this->extension = array_shift($parts);
 103  
 104          if (!empty($parts)) {
 105              $this->section = array_shift($parts);
 106          }
 107  
 108          // Set the toolbar
 109          $this->addToolbar();
 110  
 111          // Display the template
 112          parent::display($tpl);
 113      }
 114  
 115      /**
 116       * Add the page title and toolbar.
 117       *
 118       * @return  void
 119       *
 120       * @since  4.0.0
 121       */
 122      protected function addToolbar()
 123      {
 124          Factory::getApplication()->input->set('hidemainmenu', true);
 125  
 126          $user       = $this->getCurrentUser();
 127          $userId     = $user->id;
 128          $isNew      = empty($this->item->id);
 129  
 130          $canDo = WorkflowHelper::getActions($this->extension, 'workflow', $this->item->id);
 131  
 132          ToolbarHelper::title(empty($this->item->id) ? Text::_('COM_WORKFLOW_WORKFLOWS_ADD') : Text::_('COM_WORKFLOW_WORKFLOWS_EDIT'), 'address');
 133  
 134          $toolbarButtons = [];
 135  
 136          if ($isNew) {
 137              // For new records, check the create permission.
 138              if ($canDo->get('core.create')) {
 139                  ToolbarHelper::apply('workflow.apply');
 140                  $toolbarButtons = [['save', 'workflow.save'], ['save2new', 'workflow.save2new']];
 141              }
 142  
 143              ToolbarHelper::saveGroup(
 144                  $toolbarButtons,
 145                  'btn-success'
 146              );
 147  
 148              ToolbarHelper::cancel(
 149                  'workflow.cancel'
 150              );
 151          } else {
 152              // Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
 153              $itemEditable = $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId);
 154  
 155              if ($itemEditable) {
 156                  ToolbarHelper::apply('workflow.apply');
 157                  $toolbarButtons = [['save', 'workflow.save']];
 158  
 159                  // We can save this record, but check the create permission to see if we can return to make a new one.
 160                  if ($canDo->get('core.create')) {
 161                      $toolbarButtons[] = ['save2new', 'workflow.save2new'];
 162                      $toolbarButtons[] = ['save2copy', 'workflow.save2copy'];
 163                  }
 164              }
 165  
 166              ToolbarHelper::saveGroup(
 167                  $toolbarButtons,
 168                  'btn-success'
 169              );
 170  
 171              ToolbarHelper::cancel(
 172                  'workflow.cancel',
 173                  'JTOOLBAR_CLOSE'
 174              );
 175          }
 176      }
 177  }


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