public function SvgImageFieldItem::fieldSettingsForm in SVG Image Field 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldType/SvgImageFieldItem.php \Drupal\svg_image_field\Plugin\Field\FieldType\SvgImageFieldItem::fieldSettingsForm()
- 2.1.x src/Plugin/Field/FieldType/SvgImageFieldItem.php \Drupal\svg_image_field\Plugin\Field\FieldType\SvgImageFieldItem::fieldSettingsForm()
Returns a form for the field-level settings.
Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.
Return value
array The form definition for the field settings.
Overrides FileItem::fieldSettingsForm
File
- src/
Plugin/ Field/ FieldType/ SvgImageFieldItem.php, line 169
Class
- SvgImageFieldItem
- Plugin implementation of the 'svg_image' field type.
Namespace
Drupal\svg_image_field\Plugin\Field\FieldTypeCode
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
// Get base form from FileItem.
$element = parent::fieldSettingsForm($form, $form_state);
$settings = $this
->getSettings();
// Remove the description option.
unset($element['description_field']);
$element['file_extensions']['#disabled'] = TRUE;
// Add title and alt configuration options.
$element['alt_field'] = [
'#type' => 'checkbox',
'#title' => t('Enable <em>Alt</em> field'),
'#default_value' => $settings['alt_field'],
'#description' => t('The alt attribute may be used by search engines, screen readers, and when the image cannot be loaded. Enabling this field is recommended.'),
'#weight' => 9,
];
$element['alt_field_required'] = [
'#type' => 'checkbox',
'#title' => t('<em>Alt</em> field required'),
'#default_value' => $settings['alt_field_required'],
'#description' => t('Making this field required is recommended.'),
'#weight' => 10,
'#states' => [
'visible' => [
':input[name="settings[alt_field]"]' => [
'checked' => TRUE,
],
],
],
];
$element['title_field'] = [
'#type' => 'checkbox',
'#title' => t('Enable <em>Title</em> field'),
'#default_value' => $settings['title_field'],
'#description' => t('The title attribute is used as a tooltip when the mouse hovers over the image. Enabling this field is not recommended as it can cause problems with screen readers.'),
'#weight' => 11,
];
$element['title_field_required'] = [
'#type' => 'checkbox',
'#title' => t('<em>Title</em> field required'),
'#default_value' => $settings['title_field_required'],
'#weight' => 12,
'#states' => [
'visible' => [
':input[name="settings[title_field]"]' => [
'checked' => TRUE,
],
],
],
];
// Add default_image element.
static::defaultImageForm($element, $settings);
$element['default_image']['#description'] = t("If no image is uploaded, this image will be shown on display and will override the field's default image.");
return $element;
}