[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2011 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  // phpcs:disable PSR1.Files.SideEffects
  13  \defined('JPATH_PLATFORM') or die;
  14  // phpcs:enable PSR1.Files.SideEffects
  15  
  16  /**
  17   * Form Field class for the Joomla Platform.
  18   * Supports a URL text field
  19   *
  20   * @link   https://html.spec.whatwg.org/multipage/input.html#url-state-(type=url)
  21   * @see    \Joomla\CMS\Form\Rule\UrlRule for validation of full urls
  22   * @since  1.7.0
  23   */
  24  class UrlField extends TextField
  25  {
  26      /**
  27       * The form field type.
  28       *
  29       * @var    string
  30       * @since  1.7.0
  31       */
  32      protected $type = 'Url';
  33  
  34      /**
  35       * Name of the layout being used to render the field
  36       *
  37       * @var    string
  38       * @since  3.7
  39       */
  40      protected $layout = 'joomla.form.field.url';
  41  
  42      /**
  43       * Method to get the field input markup.
  44       *
  45       * @return  string  The field input markup.
  46       *
  47       * @since   3.1.2 (CMS)
  48       */
  49      protected function getInput()
  50      {
  51          // Trim the trailing line in the layout file
  52          return rtrim($this->getRenderer($this->layout)->render($this->getLayoutData()), PHP_EOL);
  53      }
  54  
  55      /**
  56       * Method to get the data to be passed to the layout for rendering.
  57       *
  58       * @return  array
  59       *
  60       * @since 3.7
  61       */
  62      protected function getLayoutData()
  63      {
  64          $data = parent::getLayoutData();
  65  
  66          // Initialize some field attributes.
  67          $maxLength    = !empty($this->maxLength) ? ' maxlength="' . $this->maxLength . '"' : '';
  68  
  69          // Note that the input type "url" is suitable only for external URLs, so if internal URLs are allowed
  70          // we have to use the input type "text" instead.
  71          $inputType    = $this->element['relative'] ? 'type="text"' : 'type="url"';
  72  
  73          $extraData = array(
  74              'maxLength' => $maxLength,
  75              'inputType' => $inputType,
  76          );
  77  
  78          return array_merge($data, $extraData);
  79      }
  80  }


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