diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php index e0ba02d..5062450 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php @@ -53,14 +53,20 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) /** * {@inheritdoc} */ - protected function allowedValuesDescription() { - $description = '

' . t('The possible values this field can contain. Enter one value per line, in the format key|label.'); - $description .= '
' . t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.'); - $description .= '
' . t('The label is optional: if a line contains a single number, it will be used as key and label.'); - $description .= '
' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.'); - $description .= '

'; - $description .= '

' . t('Allowed HTML tags in labels: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '

'; - return $description; + protected function allowedValuesHelpElement() { + $element = array( + '#type' => 'inline_template', + '#template' => '

{{ var1 }}
{{ var2 }}
{{ var3 }}
{{ var5 }}

{{ var5 }} {{ tags }}

', + '#context' => array( + 'var1' => t('The possible values this field can contain. Enter one value per line, in the format key|label.'), + 'var2' => t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.'), + 'var3' => t('The label is optional: if a line contains a single number, it will be used as key and label.'), + 'var4' => t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.'), + 'var5' => t('Allowed HTML tags in labels:'), + 'tags' => _field_filter_xss_display_allowed_tags(), + ), + ); + return $element; } /** diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php index c049878..9541563 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php @@ -53,14 +53,20 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) /** * {@inheritdoc} */ - protected function allowedValuesDescription() { - $description = '

' . t('The possible values this field can contain. Enter one value per line, in the format key|label.'); - $description .= '
' . t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.'); - $description .= '
' . t('The label is optional: if a line contains a single number, it will be used as key and label.'); - $description .= '
' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.'); - $description .= '

'; - $description .= '

' . t('Allowed HTML tags in labels: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '

'; - return $description; + protected function allowedValuesHelpElement() { + $element = array( + '#type' => 'inline_template', + '#template' => '

{{ var1 }}
{{ var2 }}
{{ var3 }}
{{ var4 }}

{{ var5 }} {{ tags }}

', + '#context' => array( + 'var1' => t('The possible values this field can contain. Enter one value per line, in the format key|label.'), + 'var2' => t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.'), + 'var3' => t('The label is optional: if a line contains a single number, it will be used as key and label.'), + 'var4' => t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.'), + 'var5' => t('Allowed HTML tags in labels:'), + 'tags' => _field_filter_xss_display_allowed_tags(), + ), + ); + return $element; } /** diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php b/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php index ede945e..e3533ea 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php @@ -89,7 +89,12 @@ public function settingsForm(array &$form, array &$form_state, $has_data) { '#allowed_values' => $allowed_values, ); - $element['allowed_values']['#description'] = $this->allowedValuesDescription(); + $allowed_values_help_element = $this->allowedValuesHelpElement(); + + if (!empty($allowed_values_help_element)) { + $element['allowed_values_help'] = $allowed_values_help_element; + $element['allowed_values_help']['#access'] = empty($allowed_values_function); + } $element['allowed_values_function'] = array( '#type' => 'item', @@ -105,10 +110,22 @@ public function settingsForm(array &$form, array &$form_state, $has_data) { /** * Provides the field type specific allowed values form element #description. * + * @deprecated + * * @return string * The field type allowed values form specific description. */ - abstract protected function allowedValuesDescription(); + protected function allowedValuesDescription() { + return ''; + } + + /** + * Provides the field type specific allowed values help form element. + * + * @return array + * The field type allowed values form help text as an options array. + */ + abstract protected function allowedValuesHelpElement(); /** * #element_validate callback for options field allowed values. diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListTextItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListTextItem.php index 1cf34b4..a431000 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListTextItem.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListTextItem.php @@ -55,13 +55,19 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) /** * {@inheritdoc} */ - protected function allowedValuesDescription() { - $description = '

' . t('The possible values this field can contain. Enter one value per line, in the format key|label.'); - $description .= '
' . t('The key is the stored value. The label will be used in displayed values and edit forms.'); - $description .= '
' . t('The label is optional: if a line contains a single string, it will be used as key and label.'); - $description .= '

'; - $description .= '

' . t('Allowed HTML tags in labels: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '

'; - return $description; + protected function allowedValuesHelpElement() { + $element = array( + '#type' => 'inline_template', + '#template' => '

{{ var1 }}
{{ var2 }}
{{ var3 }}

{{ var4 }} {{ tags }}

', + '#context' => array( + 'var1' => t('The possible values this field can contain. Enter one value per line, in the format key|label.'), + 'var2' => t('The key is the stored value. The label will be used in displayed values and edit forms.'), + 'var3' => t('The label is optional: if a line contains a single string, it will be used as key and label.'), + 'var4' => t('Allowed HTML tags in labels: '), + 'tags' => _field_filter_xss_display_allowed_tags(), + ), + ); + return $element; } /**