You are here

public function TokenFieldForm::buildForm in Display Suite 8.4

Same name and namespace in other branches
  1. 8.2 src/Form/TokenFieldForm.php \Drupal\ds\Form\TokenFieldForm::buildForm()
  2. 8.3 src/Form/TokenFieldForm.php \Drupal\ds\Form\TokenFieldForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FieldFormBase::buildForm

File

src/Form/TokenFieldForm.php, line 27

Class

TokenFieldForm
Configures token fields.

Namespace

Drupal\ds\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $field_key = '') {
  $form = parent::buildForm($form, $form_state, $field_key);
  $field = $this->field;
  $form['content'] = [
    '#type' => 'text_format',
    '#title' => $this
      ->t('Field content'),
    '#default_value' => isset($field['properties']['content']['value']) ? $field['properties']['content']['value'] : '',
    '#format' => isset($field['properties']['content']['format']) ? $field['properties']['content']['format'] : 'plain_text',
    '#base_type' => 'textarea',
    '#required' => TRUE,
  ];

  // Token support.
  if (\Drupal::moduleHandler()
    ->moduleExists('token')) {
    $form['tokens'] = [
      '#title' => $this
        ->t('Tokens'),
      '#type' => 'container',
      '#states' => [
        'invisible' => [
          'input[name="use_token"]' => [
            'checked' => FALSE,
          ],
        ],
      ],
    ];
    $form['tokens']['help'] = [
      '#theme' => 'token_tree_link',
      '#token_types' => 'all',
      '#global_types' => FALSE,
      '#dialog' => TRUE,
    ];
  }
  return $form;
}