1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Form
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 JFormHelper::loadFieldClass('text');
13
14 /**
15 * Form Field class for the Joomla Platform.
16 * Supports a URL text field
17 *
18 * @link http://www.w3.org/TR/html-markup/input.url.html#input.url
19 * @see JFormRuleUrl for validation of full urls
20 * @since 11.1
21 */
22 class JFormFieldUrl extends JFormFieldText
23 {
24 /**
25 * The form field type.
26 *
27 * @var string
28 * @since 11.1
29 */
30 protected $type = 'Url';
31
32 /**
33 * Name of the layout being used to render the field
34 *
35 * @var string
36 * @since 3.7
37 */
38 protected $layout = 'joomla.form.field.url';
39
40 /**
41 * Method to get the field input markup.
42 *
43 * @return string The field input markup.
44 *
45 * @since 3.1.2 (CMS)
46 */
47 protected function getInput()
48 {
49 // Trim the trailing line in the layout file
50 return rtrim($this->getRenderer($this->layout)->render($this->getLayoutData()), PHP_EOL);
51 }
52
53 /**
54 * Method to get the data to be passed to the layout for rendering.
55 *
56 * @return array
57 *
58 * @since 3.7
59 */
60 protected function getLayoutData()
61 {
62 $data = parent::getLayoutData();
63
64 // Initialize some field attributes.
65 $maxLength = !empty($this->maxLength) ? ' maxlength="' . $this->maxLength . '"' : '';
66
67 // Note that the input type "url" is suitable only for external URLs, so if internal URLs are allowed
68 // we have to use the input type "text" instead.
69 $inputType = $this->element['relative'] ? 'type="text"' : 'type="url"';
70
71 $extraData = array(
72 'maxLength' => $maxLength,
73 'inputType' => $inputType,
74 );
75
76 return array_merge($data, $extraData);
77 }
78 }
79