public function SocialMediaLinksFieldDefaultFormatter::settingsForm in Social Media Links Block and Field 8.2
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
- modules/
social_media_links_field/ src/ Plugin/ Field/ FieldFormatter/ SocialMediaLinksFieldDefaultFormatter.php, line 86
Class
- SocialMediaLinksFieldDefaultFormatter
- Plugin implementation of the 'social_media_links_field_default' formatter.
Namespace
Drupal\social_media_links_field\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$config = $this
->getSettings();
$element['appearance'] = [
'#type' => 'details',
'#title' => $this
->t('Appearance'),
'#tree' => TRUE,
];
$element['appearance']['orientation'] = [
'#type' => 'select',
'#title' => $this
->t('Orientation'),
'#options' => [
'v' => $this
->t('vertical'),
'h' => $this
->t('horizontal'),
],
'#default_value' => isset($config['appearance']['orientation']) ? $config['appearance']['orientation'] : 'h',
];
$element['appearance']['show_name'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show name'),
'#description' => $this
->t('Show the platform name next to the icon.'),
'#default_value' => isset($config['appearance']['show_name']) ? $config['appearance']['show_name'] : 0,
];
// Link Attributes.
$element['link_attributes'] = [
'#type' => 'details',
'#title' => $this
->t('Link attributes'),
'#tree' => TRUE,
];
$element['link_attributes']['target'] = [
'#type' => 'select',
'#title' => $this
->t('Default target'),
'#default_value' => isset($config['link_attributes']['target']) ? $config['link_attributes']['target'] : '<none>',
'#options' => [
'<none>' => $this
->t('Remove target attribute'),
'_blank' => $this
->t('Open in a new browser window or tab (_blank)'),
'_self' => $this
->t('Open in the current window (_self)'),
'_parent' => $this
->t('Open in the frame that is superior to the frame the link is in (_parent)'),
'_top' => $this
->t('Cancel all frames and open in full browser window (_top)'),
],
];
$element['link_attributes']['rel'] = [
'#type' => 'select',
'#title' => $this
->t('Default rel'),
'#default_value' => isset($config['link_attributes']['rel']) ? $config['link_attributes']['rel'] : '<none>',
'#options' => [
'<none>' => $this
->t('Remove rel attribute'),
'nofollow' => $this
->t('Set nofollow'),
],
];
return $element;
}