[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Form/Field/ -> ModulepositionField.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2009 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\Form\Field;
  11  
  12  use Joomla\CMS\Application\ApplicationHelper;
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Form\Form;
  15  use Joomla\CMS\HTML\HTMLHelper;
  16  use Joomla\CMS\Language\Text;
  17  
  18  // phpcs:disable PSR1.Files.SideEffects
  19  \defined('JPATH_PLATFORM') or die;
  20  // phpcs:enable PSR1.Files.SideEffects
  21  
  22  /**
  23   * Module Position field.
  24   *
  25   * @since  1.6
  26   */
  27  class ModulepositionField extends TextField
  28  {
  29      /**
  30       * The form field type.
  31       *
  32       * @var    string
  33       * @since  1.6
  34       */
  35      protected $type = 'ModulePosition';
  36  
  37      /**
  38       * The client ID.
  39       *
  40       * @var    integer
  41       * @since  3.2
  42       */
  43      protected $clientId;
  44  
  45      /**
  46       * Method to get certain otherwise inaccessible properties from the form field object.
  47       *
  48       * @param   string  $name  The property name for which to get the value.
  49       *
  50       * @return  mixed  The property value or null.
  51       *
  52       * @since   3.2
  53       */
  54      public function __get($name)
  55      {
  56          if ($name === 'clientId') {
  57              return $this->clientId;
  58          }
  59  
  60          return parent::__get($name);
  61      }
  62  
  63      /**
  64       * Method to set certain otherwise inaccessible properties of the form field object.
  65       *
  66       * @param   string  $name   The property name for which to set the value.
  67       * @param   mixed   $value  The value of the property.
  68       *
  69       * @return  void
  70       *
  71       * @since   3.2
  72       */
  73      public function __set($name, $value)
  74      {
  75          switch ($name) {
  76              case 'clientId':
  77                  $this->clientId = (string) $value;
  78                  break;
  79  
  80              default:
  81                  parent::__set($name, $value);
  82          }
  83      }
  84  
  85      /**
  86       * Method to attach a Form object to the field.
  87       *
  88       * @param   \SimpleXMLElement  $element  The SimpleXMLElement object representing the `<field>` tag for the form field object.
  89       * @param   mixed              $value    The form field value to validate.
  90       * @param   string             $group    The field name group control value. This acts as an array container for the field.
  91       *                                       For example if the field has name="foo" and the group value is set to "bar" then the
  92       *                                       full field name would end up being "bar[foo]".
  93       *
  94       * @return  boolean  True on success.
  95       *
  96       * @see     FormField::setup()
  97       * @since   3.2
  98       */
  99      public function setup(\SimpleXMLElement $element, $value, $group = null)
 100      {
 101          $result = parent::setup($element, $value, $group);
 102  
 103          if ($result === true) {
 104              // Get the client id.
 105              $clientId = $this->element['client_id'];
 106  
 107              if (!isset($clientId)) {
 108                  $clientName = $this->element['client'];
 109  
 110                  if (isset($clientName)) {
 111                      $client = ApplicationHelper::getClientInfo($clientName, true);
 112                      $clientId = $client->id;
 113                  }
 114              }
 115  
 116              if (!isset($clientId) && $this->form instanceof Form) {
 117                  $clientId = $this->form->getValue('client_id');
 118              }
 119  
 120              $this->clientId = (int) $clientId;
 121          }
 122  
 123          return $result;
 124      }
 125  
 126      /**
 127       * Method to get the field input markup.
 128       *
 129       * @return  string  The field input markup.
 130       *
 131       * @since   1.6
 132       */
 133      protected function getInput()
 134      {
 135          // Build the script.
 136          $script = array();
 137          $script[] = '    function jSelectPosition_' . $this->id . '(name) {';
 138          $script[] = '        document.getElementById("' . $this->id . '").value = name;';
 139          $script[] = '        jModalClose();';
 140          $script[] = '    }';
 141  
 142          // Add the script to the document head.
 143          Factory::getDocument()->addScriptDeclaration(implode("\n", $script));
 144  
 145          // Setup variables for display.
 146          $html = array();
 147          $link = 'index.php?option=com_modules&view=positions&layout=modal&tmpl=component&function=jSelectPosition_' . $this->id
 148              . '&amp;client_id=' . $this->clientId;
 149  
 150          // The current user display field.
 151          $html[] = '<div class="input-append">';
 152          $html[] = parent::getInput()
 153              . '<a class="btn" title="' . Text::_('COM_MODULES_CHANGE_POSITION_TITLE') . '" href="' . $link
 154              . '" data-bs-toggle="modal" data-bs-target="#modulePositionModal">'
 155              . Text::_('COM_MODULES_CHANGE_POSITION_BUTTON') . '</a>';
 156  
 157          $html[] = HTMLHelper::_(
 158              'bootstrap.renderModal',
 159              'modulePositionModal',
 160              array(
 161                  'url'    => $link,
 162                  'title'  => Text::_('COM_MODULES_CHANGE_POSITION_BUTTON'),
 163                  'height' => '100%',
 164                  'width'  => '100%',
 165                  'modalWidth'  => '800',
 166                  'bodyHeight'  => '450',
 167                  'footer' => '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" aria-hidden="true">'
 168                      . Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>'
 169              )
 170          );
 171          $html[] = '</div>';
 172  
 173          return implode("\n", $html);
 174      }
 175  }


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