You are here

public function LinkFormatter::settingsForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 98
Contains \Drupal\link\Plugin\Field\FieldFormatter\LinkFormatter.

Class

LinkFormatter
Plugin implementation of the 'link' formatter.

Namespace

Drupal\link\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = parent::settingsForm($form, $form_state);
  $elements['trim_length'] = array(
    '#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'] = array(
    '#type' => 'checkbox',
    '#title' => t('URL only'),
    '#default_value' => $this
      ->getSetting('url_only'),
    '#access' => $this
      ->getPluginId() == 'link',
  );
  $elements['url_plain'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show URL as plain text'),
    '#default_value' => $this
      ->getSetting('url_plain'),
    '#access' => $this
      ->getPluginId() == 'link',
    '#states' => array(
      'visible' => array(
        ':input[name*="url_only"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $elements['rel'] = array(
    '#type' => 'checkbox',
    '#title' => t('Add rel="nofollow" to links'),
    '#return_value' => 'nofollow',
    '#default_value' => $this
      ->getSetting('rel'),
  );
  $elements['target'] = array(
    '#type' => 'checkbox',
    '#title' => t('Open link in new window'),
    '#return_value' => '_blank',
    '#default_value' => $this
      ->getSetting('target'),
  );
  return $elements;
}