[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2007 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 with a confirm dialog
  20   *
  21   * @method self message(string $value)
  22   * @method bool getMessage()
  23   *
  24   * @since  3.0
  25   */
  26  class ConfirmButton extends StandardButton
  27  {
  28      /**
  29       * Prepare options for this button.
  30       *
  31       * @param   array  $options  The options about this button.
  32       *
  33       * @return  void
  34       *
  35       * @since  4.0.0
  36       */
  37      protected function prepareOptions(array &$options)
  38      {
  39          $options['message'] = Text::_($options['message'] ?? '');
  40  
  41          parent::prepareOptions($options);
  42      }
  43  
  44      /**
  45       * Fetch the HTML for the button
  46       *
  47       * @param   string   $type      Unused string.
  48       * @param   string   $msg       Message to render
  49       * @param   string   $name      Name to be used as apart of the id
  50       * @param   string   $text      Button text
  51       * @param   string   $task      The task associated with the button
  52       * @param   boolean  $list      True to allow use of lists
  53       * @param   boolean  $hideMenu  True to hide the menu on click
  54       *
  55       * @return  string   HTML string for the button
  56       *
  57       * @since   3.0
  58       *
  59       * @deprecated  5.0 Use render() instead.
  60       */
  61      public function fetchButton($type = 'Confirm', $msg = '', $name = '', $text = '', $task = '', $list = true, $hideMenu = false)
  62      {
  63          $this->name($name)
  64              ->text($text)
  65              ->listCheck($list)
  66              ->message($msg)
  67              ->task($task);
  68  
  69          return $this->renderButton($this->options);
  70      }
  71  
  72      /**
  73       * Get the JavaScript command for the button
  74       *
  75       * @return  string  JavaScript command string
  76       *
  77       * @since   3.0
  78       */
  79      protected function _getCommand()
  80      {
  81          Text::script($this->getListCheckMessage() ?: 'JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST');
  82          Text::script('ERROR');
  83  
  84          $msg = $this->getMessage();
  85  
  86          $cmd = "if (confirm('" . $msg . "')) { Joomla.submitbutton('" . $this->getTask() . "'); }";
  87  
  88          if ($this->getListCheck()) {
  89              $message = "{'error': [Joomla.Text._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST')]}";
  90              $alert = 'Joomla.renderMessages(' . $message . ')';
  91              $cmd   = 'if (document.adminForm.boxchecked.value == 0) { ' . $alert . ' } else { ' . $cmd . ' }';
  92          }
  93  
  94          return $cmd;
  95      }
  96  
  97      /**
  98       * Method to configure available option accessors.
  99       *
 100       * @return  array
 101       *
 102       * @since   4.0.0
 103       */
 104      protected static function getAccessors(): array
 105      {
 106          return array_merge(
 107              parent::getAccessors(),
 108              [
 109                  'message',
 110              ]
 111          );
 112      }
 113  }


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