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 /**
13 * Form Field class for the Joomla Platform.
14 * Provides spacer markup to be used in form layouts.
15 *
16 * @since 11.1
17 */
18 class JFormFieldSpacer extends JFormField
19 {
20 /**
21 * The form field type.
22 *
23 * @var string
24 * @since 11.1
25 */
26 protected $type = 'Spacer';
27
28 /**
29 * Method to get the field input markup for a spacer.
30 * The spacer does not have accept input.
31 *
32 * @return string The field input markup.
33 *
34 * @since 11.1
35 */
36 protected function getInput()
37 {
38 return ' ';
39 }
40
41 /**
42 * Method to get the field label markup for a spacer.
43 * Use the label text or name from the XML element as the spacer or
44 * Use a hr="true" to automatically generate plain hr markup
45 *
46 * @return string The field label markup.
47 *
48 * @since 11.1
49 */
50 protected function getLabel()
51 {
52 $html = array();
53 $class = !empty($this->class) ? ' class="' . $this->class . '"' : '';
54 $html[] = '<span class="spacer">';
55 $html[] = '<span class="before"></span>';
56 $html[] = '<span' . $class . '>';
57
58 if ((string) $this->element['hr'] == 'true')
59 {
60 $html[] = '<hr' . $class . ' />';
61 }
62 else
63 {
64 $label = '';
65
66 // Get the label text from the XML element, defaulting to the element name.
67 $text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
68 $text = $this->translateLabel ? JText::_($text) : $text;
69
70 // Build the class for the label.
71 $class = !empty($this->description) ? 'hasTooltip' : '';
72 $class = $this->required == true ? $class . ' required' : $class;
73
74 // Add the opening label tag and main attributes attributes.
75 $label .= '<label id="' . $this->id . '-lbl" class="' . $class . '"';
76
77 // If a description is specified, use it to build a tooltip.
78 if (!empty($this->description))
79 {
80 JHtml::_('bootstrap.tooltip');
81 $label .= ' title="' . JHtml::_('tooltipText', trim($text, ':'), JText::_($this->description), 0) . '"';
82 }
83
84 // Add the label text and closing tag.
85 $label .= '>' . $text . '</label>';
86 $html[] = $label;
87 }
88
89 $html[] = '</span>';
90 $html[] = '<span class="after"></span>';
91 $html[] = '</span>';
92
93 return implode('', $html);
94 }
95
96 /**
97 * Method to get the field title.
98 *
99 * @return string The field title.
100 *
101 * @since 11.1
102 */
103 protected function getTitle()
104 {
105 return $this->getLabel();
106 }
107
108 /**
109 * Method to get a control group with label and input.
110 *
111 * @param array $options Options to be passed into the rendering of the field
112 *
113 * @return string A string containing the html for the control group
114 *
115 * @since 3.7.3
116 */
117 public function renderField($options = array())
118 {
119 $options['class'] = empty($options['class']) ? 'field-spacer' : $options['class'] . ' field-spacer';
120
121 return parent::renderField($options);
122 }
123 }
124