spacer.php
3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* @package Joomla.Platform
* @subpackage Form
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* Form Field class for the Joomla Platform.
* Provides spacer markup to be used in form layouts.
*
* @since 1.7.0
*/
class JFormFieldSpacer extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 1.7.0
*/
protected $type = 'Spacer';
/**
* Method to get the field input markup for a spacer.
* The spacer does not have accept input.
*
* @return string The field input markup.
*
* @since 1.7.0
*/
protected function getInput()
{
return ' ';
}
/**
* Method to get the field label markup for a spacer.
* Use the label text or name from the XML element as the spacer or
* Use a hr="true" to automatically generate plain hr markup
*
* @return string The field label markup.
*
* @since 1.7.0
*/
protected function getLabel()
{
$html = array();
$class = !empty($this->class) ? ' class="' . $this->class . '"' : '';
$html[] = '<span class="spacer">';
$html[] = '<span class="before"></span>';
$html[] = '<span' . $class . '>';
if ((string) $this->element['hr'] == 'true')
{
$html[] = '<hr' . $class . ' />';
}
else
{
$label = '';
// Get the label text from the XML element, defaulting to the element name.
$text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
$text = $this->translateLabel ? JText::_($text) : $text;
// Build the class for the label.
$class = !empty($this->description) ? 'hasPopover' : '';
$class = $this->required == true ? $class . ' required' : $class;
// Add the opening label tag and main attributes attributes.
$label .= '<label id="' . $this->id . '-lbl" class="' . $class . '"';
// If a description is specified, use it to build a tooltip.
if (!empty($this->description))
{
JHtml::_('bootstrap.popover');
$label .= ' title="' . htmlspecialchars(trim($text, ':'), ENT_COMPAT, 'UTF-8') . '"';
$label .= ' data-content="' . htmlspecialchars(
$this->translateDescription ? JText::_($this->description) : $this->description,
ENT_COMPAT,
'UTF-8'
) . '"';
if (JFactory::getLanguage()->isRtl())
{
$label .= ' data-placement="left"';
}
}
// Add the label text and closing tag.
$label .= '>' . $text . '</label>';
$html[] = $label;
}
$html[] = '</span>';
$html[] = '<span class="after"></span>';
$html[] = '</span>';
return implode('', $html);
}
/**
* Method to get the field title.
*
* @return string The field title.
*
* @since 1.7.0
*/
protected function getTitle()
{
return $this->getLabel();
}
/**
* Method to get a control group with label and input.
*
* @param array $options Options to be passed into the rendering of the field
*
* @return string A string containing the html for the control group
*
* @since 3.7.3
*/
public function renderField($options = array())
{
$options['class'] = empty($options['class']) ? 'field-spacer' : $options['class'] . ' field-spacer';
return parent::renderField($options);
}
}