You are here

public function BehaviorForm::buildForm in Synonyms 2.0.x

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 ConfigFormBase::buildForm

File

src/Form/BehaviorForm.php, line 153

Class

BehaviorForm
The behavior form for given entity type.

Namespace

Drupal\synonyms\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $replacements = [
    '#theme' => 'item_list',
    '#list_type' => 'ul',
    '#items' => [],
  ];
  foreach ($this
    ->formatWordingAvailableTokens() as $token => $token_info) {
    $replacements['#items'][] = Html::escape($token) . ': ' . $token_info;
  }
  $replacements = $this->renderer
    ->renderRoot($replacements);
  foreach ($this->behaviorService
    ->getBehaviorServices() as $service_id => $service) {
    $this
      ->setNames($service_id);
    $form[$this->statusName] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('@service service', [
        '@service' => $service
          ->getTitle(),
      ]),
      '#default_value' => $this
        ->config($this
        ->getConfigName($service_id))
        ->get('status') ?: 0,
    ];
    if ($service instanceof WidgetInterface && $this
      ->showWordingForm()) {
      $form[$this->wordingName] = [
        '#type' => 'textfield',
        '#title' => $this
          ->t('@widget widget wording:', [
          '@widget' => $service
            ->getWidgetTitle(),
        ]),
        '#default_value' => $this
          ->config($this
          ->getConfigName($service_id))
          ->get('wording') ?: '',
        '#description' => $this
          ->t('Specify the wording with which @widget widget suggestions should be presented. Available replacement tokens are: @replacements If this field is left empty the @widget widget default wording will be used.', [
          '@widget' => $service
            ->getWidgetTitle(),
          '@replacements' => $replacements,
        ]),
        '#states' => [
          'visible' => [
            ':input[name="' . $this->statusName . '"]' => [
              'checked' => TRUE,
            ],
          ],
        ],
      ];
    }
  }
  return parent::buildForm($form, $form_state);
}