[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Toolbar/Button/ -> StandardButton.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\Toolbar\Button;
  11  
  12  use Joomla\CMS\Language\Text;
  13  
  14  // phpcs:disable PSR1.Files.SideEffects
  15  \defined('JPATH_PLATFORM') or die;
  16  // phpcs:enable PSR1.Files.SideEffects
  17  
  18  /**
  19   * Renders a standard button
  20   *
  21   * @since  3.0
  22   */
  23  class StandardButton extends BasicButton
  24  {
  25      /**
  26       * Property layout.
  27       *
  28       * @var  string
  29       *
  30       * @since  4.0.0
  31       */
  32      protected $layout = 'joomla.toolbar.standard';
  33  
  34      /**
  35       * Prepare options for this button.
  36       *
  37       * @param   array  $options  The options about this button.
  38       *
  39       * @return  void
  40       *
  41       * @since  4.0.0
  42       */
  43      protected function prepareOptions(array &$options)
  44      {
  45          parent::prepareOptions($options);
  46  
  47          if (empty($options['is_child'])) {
  48              $class = $this->fetchButtonClass($this->getName());
  49  
  50              $options['btnClass'] = $options['button_class'] = ($options['button_class'] ?? $class);
  51          }
  52  
  53          $options['onclick'] = $options['onclick'] ?? $this->_getCommand();
  54      }
  55  
  56      /**
  57       * Fetch the HTML for the button
  58       *
  59       * @param   string   $type    Unused string.
  60       * @param   string   $name    The name of the button icon class.
  61       * @param   string   $text    Button text.
  62       * @param   string   $task    Task associated with the button.
  63       * @param   boolean  $list    True to allow lists
  64       * @param   string   $formId  The id of action form.
  65       *
  66       * @return  string  HTML string for the button
  67       *
  68       * @since   3.0
  69       *
  70       * @deprecated  5.0 Use render() instead.
  71       */
  72      public function fetchButton($type = 'Standard', $name = '', $text = '', $task = '', $list = true, $formId = null)
  73      {
  74          $this->name($name)
  75              ->text($text)
  76              ->task($task)
  77              ->listCheck($list);
  78  
  79          if ($formId !== null) {
  80              $this->form($formId);
  81          }
  82  
  83          return $this->renderButton($this->options);
  84      }
  85  
  86      /**
  87       * Fetch button class for standard buttons.
  88       *
  89       * @param   string  $name  The button name.
  90       *
  91       * @return  string
  92       *
  93       * @since   4.0.0
  94       */
  95      public function fetchButtonClass(string $name): string
  96      {
  97          switch ($name) {
  98              case 'apply':
  99              case 'new':
 100              case 'save':
 101              case 'save-new':
 102              case 'save-copy':
 103              case 'save-close':
 104              case 'publish':
 105                  return 'btn btn-success';
 106  
 107              case 'featured':
 108                  return 'btn btn-warning';
 109  
 110              case 'cancel':
 111              case 'trash':
 112              case 'delete':
 113              case 'unpublish':
 114                  return 'btn btn-danger';
 115  
 116              default:
 117                  return 'btn btn-primary';
 118          }
 119      }
 120  
 121      /**
 122       * Get the JavaScript command for the button
 123       *
 124       * @return  string   JavaScript command string
 125       *
 126       * @since   3.0
 127       */
 128      protected function _getCommand()
 129      {
 130          Text::script($this->getListCheckMessage() ?: 'JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST');
 131          Text::script('ERROR');
 132  
 133          $cmd = "Joomla.submitbutton('" . $this->getTask() . "');";
 134  
 135          if ($this->getListCheck()) {
 136              $messages = "{error: [Joomla.Text._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST')]}";
 137              $alert = 'Joomla.renderMessages(' . $messages . ')';
 138              $cmd   = 'if (document.adminForm.boxchecked.value == 0) { ' . $alert . ' } else { ' . $cmd . ' }';
 139          }
 140  
 141          return $cmd;
 142      }
 143  }


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