/libraries/joomla/form/fields/spacer.php

https://bitbucket.org/eternaware/joomus · PHP · 111 lines · 49 code · 12 blank · 50 comment · 4 complexity · 412ab1f71d20cab06c12edb6ff50f90b MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage Form
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die;
  10. /**
  11. * Form Field class for the Joomla Platform.
  12. * Provides spacer markup to be used in form layouts.
  13. *
  14. * @package Joomla.Platform
  15. * @subpackage Form
  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. * Method to get the field input markup for a spacer.
  29. * The spacer does not have accept input.
  30. *
  31. * @return string The field input markup.
  32. *
  33. * @since 11.1
  34. */
  35. protected function getInput()
  36. {
  37. return ' ';
  38. }
  39. /**
  40. * Method to get the field label markup for a spacer.
  41. * Use the label text or name from the XML element as the spacer or
  42. * Use a hr="true" to automatically generate plain hr markup
  43. *
  44. * @return string The field label markup.
  45. *
  46. * @since 11.1
  47. */
  48. protected function getLabel()
  49. {
  50. $html = array();
  51. $class = $this->element['class'] ? (string) $this->element['class'] : '';
  52. $html[] = '<span class="spacer">';
  53. $html[] = '<span class="before"></span>';
  54. $html[] = '<span class="' . $class . '">';
  55. if ((string) $this->element['hr'] == 'true')
  56. {
  57. $html[] = '<hr class="' . $class . '" />';
  58. }
  59. else
  60. {
  61. $label = '';
  62. // Get the label text from the XML element, defaulting to the element name.
  63. $text = $this->element['label'] ? (string) $this->element['label'] : (string) $this->element['name'];
  64. $text = $this->translateLabel ? JText::_($text) : $text;
  65. // Build the class for the label.
  66. $class = !empty($this->description) ? 'hasTip' : '';
  67. $class = $this->required == true ? $class . ' required' : $class;
  68. // Add the opening label tag and main attributes attributes.
  69. $label .= '<label id="' . $this->id . '-lbl" class="' . $class . '"';
  70. // If a description is specified, use it to build a tooltip.
  71. if (!empty($this->description))
  72. {
  73. $label .= ' title="'
  74. . htmlspecialchars(
  75. trim($text, ':') . '::' . ($this->translateDescription ? JText::_($this->description) : $this->description),
  76. ENT_COMPAT, 'UTF-8'
  77. ) . '"';
  78. }
  79. // Add the label text and closing tag.
  80. $label .= '>' . $text . '</label>';
  81. $html[] = $label;
  82. }
  83. $html[] = '</span>';
  84. $html[] = '<span class="after"></span>';
  85. $html[] = '</span>';
  86. return implode('', $html);
  87. }
  88. /**
  89. * Method to get the field title.
  90. *
  91. * @return string The field title.
  92. *
  93. * @since 11.1
  94. */
  95. protected function getTitle()
  96. {
  97. return $this->getLabel();
  98. }
  99. }