You are here

public function WebformEntityReferenceLinkFormatter::settingsForm in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/Field/FieldFormatter/WebformEntityReferenceLinkFormatter.php \Drupal\webform\Plugin\Field\FieldFormatter\WebformEntityReferenceLinkFormatter::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

src/Plugin/Field/FieldFormatter/WebformEntityReferenceLinkFormatter.php, line 131

Class

WebformEntityReferenceLinkFormatter
Plugin implementation of the 'Link to webform' formatter.

Namespace

Drupal\webform\Plugin\Field\FieldFormatter

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $form = parent::settingsForm($form, $form_state);
  if ($this->fieldDefinition
    ->getTargetEntityTypeId() === 'paragraph') {
    $form['message'] = [
      '#type' => 'webform_message',
      '#message_type' => 'warning',
      '#message_message' => $this
        ->t("This paragraph field's main entity will be used as the webform submission's source entity."),
      '#message_close' => TRUE,
      '#message_storage' => WebformMessage::STORAGE_SESSION,
    ];
  }
  $form['label'] = [
    '#title' => $this
      ->t('Label'),
    '#type' => 'textfield',
    '#default_value' => $this
      ->getSetting('label'),
    '#required' => TRUE,
  ];
  $dialog_options = $this->configFactory
    ->get('webform.settings')
    ->get('settings.dialog_options');
  if ($dialog_options) {
    $options = [];
    foreach ($dialog_options as $dialog_option_name => $dialog_option) {
      $options[$dialog_option_name] = isset($dialog_option['title']) ? $dialog_option['title'] : $dialog_option_name;
    }
    $form['dialog'] = [
      '#title' => $this
        ->t('Dialog'),
      '#type' => 'select',
      '#empty_option' => $this
        ->t('- Select dialog -'),
      '#default_value' => $this
        ->getSetting('dialog'),
      '#options' => $options,
    ];
    $form['attributes'] = [
      '#type' => 'webform_element_attributes',
      '#title' => $this
        ->t('Link'),
      '#default_value' => $this
        ->getSetting('attributes'),
    ];
  }
  return $form;
}