You are here

public function FileUrlWidget::settingsForm in File URL 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldWidget/FileUrlWidget.php \Drupal\file_url\Plugin\Field\FieldWidget\FileUrlWidget::settingsForm()

Returns a form to configure settings for the widget.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. 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 definition for the widget settings.

Overrides FileWidget::settingsForm

File

src/Plugin/Field/FieldWidget/FileUrlWidget.php, line 51

Class

FileUrlWidget
Plugin implementation of the 'file_url_generic' widget.

Namespace

Drupal\file_url\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = parent::settingsForm($form, $form_state);

  // Allow configuring only if the field has multiple values.
  if ($this->fieldDefinition
    ->getFieldStorageDefinition()
    ->getCardinality() !== 1) {
    $element['add_new_label'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Label for new item form'),
      '#default_value' => $this
        ->getSetting('add_new_label'),
    ];
  }
  return $element;
}