From c56805fdfa046b1d89527aa50662aa0ed079da2a Mon Sep 17 00:00:00 2001 From: Ruud van Lent Date: Thu, 7 Feb 2019 17:42:30 +0100 Subject: [PATCH] Add layouts to plg_user_terms --- layouts/plugins/user/terms/label.php | 134 +++++++++++++++++++++++++ layouts/plugins/user/terms/message.php | 48 +++++++++ plugins/user/terms/field/terms.php | 110 +++++--------------- 3 files changed, 206 insertions(+), 86 deletions(-) create mode 100644 layouts/plugins/user/terms/label.php create mode 100644 layouts/plugins/user/terms/message.php diff --git a/layouts/plugins/user/terms/label.php b/layouts/plugins/user/terms/label.php new file mode 100644 index 0000000000000..7a25a21015d26 --- /dev/null +++ b/layouts/plugins/user/terms/label.php @@ -0,0 +1,134 @@ + section in form XML. + * @var boolean $hidden Is this field hidden in the form? + * @var string $hint Placeholder for the field. + * @var string $id DOM id of the field. + * @var string $label Label of the field. + * @var string $labelclass Classes to apply to the label. + * @var boolean $multiple Does this field support multiple values? + * @var string $name Name of the input field. + * @var string $onchange Onchange attribute for the field. + * @var string $onclick Onclick attribute for the field. + * @var string $pattern Pattern (Reg Ex) of value of the form field. + * @var boolean $readonly Is this field read only? + * @var boolean $repeat Allows extensions to duplicate elements. + * @var boolean $required Is this field required? + * @var integer $size Size attribute of the input. + * @var boolean $spellcheck Spellcheck state for the form field. + * @var string $validate Validation rules to apply. + * @var string $value Value attribute of the field. + * @var array $options Options available for this field. + * @var array $termsnote The terms note that needs to be displayed + * @var array $translateLabel Should the label be translated? + * @var array $translateDescription Should the description be translated? + * @var array $translateHint Should the hint be translated? + * @var array $termsArticle The Article ID holding the Terms Article + */ + +// Get the label text from the XML element, defaulting to the element name. +$text = $label ? (string) $label : (string) $name; +$text = $translateLabel ? Text::_($text) : $text; + +// Set required to true as this field is not displayed at all if not required. +$required = true; + +JHtml::_('behavior.modal'); + +// Build the class for the label. +$class = !empty($description) ? 'hasPopover' : ''; +$class = $class . ' required'; +$class = !empty($labelclass) ? $class . ' ' . $labelclass : $class; + +// Add the opening label tag and main attributes. +$label = ''; + +echo $label; diff --git a/layouts/plugins/user/terms/message.php b/layouts/plugins/user/terms/message.php new file mode 100644 index 0000000000000..60757d4bc4907 --- /dev/null +++ b/layouts/plugins/user/terms/message.php @@ -0,0 +1,48 @@ + section in form XML. + * @var boolean $hidden Is this field hidden in the form? + * @var string $hint Placeholder for the field. + * @var string $id DOM id of the field. + * @var string $label Label of the field. + * @var string $labelclass Classes to apply to the label. + * @var boolean $multiple Does this field support multiple values? + * @var string $name Name of the input field. + * @var string $onchange Onchange attribute for the field. + * @var string $onclick Onclick attribute for the field. + * @var string $pattern Pattern (Reg Ex) of value of the form field. + * @var boolean $readonly Is this field read only? + * @var boolean $repeat Allows extensions to duplicate elements. + * @var boolean $required Is this field required? + * @var integer $size Size attribute of the input. + * @var boolean $spellcheck Spellcheck state for the form field. + * @var string $validate Validation rules to apply. + * @var string $value Value attribute of the field. + * @var array $options Options available for this field. + * @var array $termsnote The terms note that needs to be displayed + * @var array $translateLabel Should the label be translated? + * @var array $translateDescription Should the description be translated? + * @var array $translateHint Should the hint be translated? + * @var array $termsArticle The Article ID holding the Terms Article + */ + +echo '
' . $termsnote . '
'; diff --git a/plugins/user/terms/field/terms.php b/plugins/user/terms/field/terms.php index 5cdf1f0ed21ed..b12bbfee63788 100644 --- a/plugins/user/terms/field/terms.php +++ b/plugins/user/terms/field/terms.php @@ -9,12 +9,8 @@ defined('JPATH_PLATFORM') or die; -use Joomla\CMS\Factory; use Joomla\CMS\Form\FormHelper; -use Joomla\CMS\HTML\HTMLHelper; -use Joomla\CMS\Language\Associations; use Joomla\CMS\Language\Text; -use Joomla\CMS\Router\Route; FormHelper::loadFieldClass('radio'); @@ -42,9 +38,8 @@ class JFormFieldterms extends JFormFieldRadio */ protected function getInput() { - $termsnote = !empty($this->element['note']) ? $this->element['note'] : Text::_('PLG_USER_TERMS_NOTE_FIELD_DEFAULT'); - - echo '
' . $termsnote . '
'; + // Display the message before the field + echo $this->getRenderer('plugins.user.terms.message')->render($this->getLayoutData()); return parent::getInput(); } @@ -63,88 +58,31 @@ protected function getLabel() return ''; } - // 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 ? Text::_($text) : $text; - - // Set required to true - $this->required = true; - - JHtml::_('behavior.modal'); - - // Build the class for the label. - $class = !empty($this->description) ? 'hasPopover' : ''; - $class = $class . ' required'; - $class = !empty($this->labelClass) ? $class . ' ' . $this->labelClass : $class; - - // Add the opening label tag and main attributes. - $label = ''; + $extraData = array( + 'termsnote' => !empty($this->element['note']) ? $this->element['note'] : Text::_('PLG_USER_TERMS_NOTE_FIELD_DEFAULT'), + 'options' => $this->getOptions(), + 'value' => (string) $this->value, + 'translateLabel' => $this->translateLabel, + 'translateDescription' => $this->translateDescription, + 'translateHint' => $this->translateHint, + 'termsArticle' => $this->element['article'] > 0 ? (int) $this->element['article'] : 0, + ); - return $label; + return array_merge($data, $extraData); } }