public function LinkFormatter::settingsForm in Drupal 9
Same name and namespace in other branches
- 8 core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php \Drupal\link\Plugin\Field\FieldFormatter\LinkFormatter::settingsForm()
Returns a form to configure settings for the formatter.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form elements for the formatter settings.
Overrides FormatterBase::settingsForm
File
- core/
modules/ link/ src/ Plugin/ Field/ FieldFormatter/ LinkFormatter.php, line 92
Class
- LinkFormatter
- Plugin implementation of the 'link' formatter.
Namespace
Drupal\link\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
$elements['trim_length'] = [
'#type' => 'number',
'#title' => t('Trim link text length'),
'#field_suffix' => t('characters'),
'#default_value' => $this
->getSetting('trim_length'),
'#min' => 1,
'#description' => t('Leave blank to allow unlimited link text lengths.'),
];
$elements['url_only'] = [
'#type' => 'checkbox',
'#title' => t('URL only'),
'#default_value' => $this
->getSetting('url_only'),
'#access' => $this
->getPluginId() == 'link',
];
$elements['url_plain'] = [
'#type' => 'checkbox',
'#title' => t('Show URL as plain text'),
'#default_value' => $this
->getSetting('url_plain'),
'#access' => $this
->getPluginId() == 'link',
'#states' => [
'visible' => [
':input[name*="url_only"]' => [
'checked' => TRUE,
],
],
],
];
$elements['rel'] = [
'#type' => 'checkbox',
'#title' => t('Add rel="nofollow" to links'),
'#return_value' => 'nofollow',
'#default_value' => $this
->getSetting('rel'),
];
$elements['target'] = [
'#type' => 'checkbox',
'#title' => t('Open link in new window'),
'#return_value' => '_blank',
'#default_value' => $this
->getSetting('target'),
];
return $elements;
}