You are here

public function NegotiationLanguageAdministrationLanguageNegotiationForm::buildForm in Administration Language Negotiation 8

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/NegotiationLanguageAdministrationLanguageNegotiationForm.php, line 47

Class

NegotiationLanguageAdministrationLanguageNegotiationForm
Class NegotiationLanguageAdministrationLanguageNegotiationForm.

Namespace

Drupal\administration_language_negotiation\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $this->config = $this
    ->config('administration_language_negotiation.negotiation');
  $manager = $this->administrationLanguageNegotiationConditionManager;
  foreach ($manager
    ->getDefinitions() as $def) {
    $condition_plugin = $manager
      ->createInstance($def['id']);
    $form_state
      ->set([
      'conditions',
      $condition_plugin
        ->getPluginId(),
    ], $condition_plugin);
    $condition_plugin
      ->setConfiguration($condition_plugin
      ->getConfiguration() + (array) $this->config
      ->get());
    $condition_form = [];
    $condition_form['#markup'] = $condition_plugin
      ->getDescription();
    $condition_form += $condition_plugin
      ->buildConfigurationForm([], $form_state);
    if (!empty($condition_form[$condition_plugin
      ->getPluginId()])) {
      $condition_form['#type'] = 'details';
      $condition_form['#open'] = TRUE;
      $condition_form['#title'] = $condition_plugin
        ->getName();
      $condition_form['#weight'] = $condition_plugin
        ->getWeight();
      $form['conditions'][$condition_plugin
        ->getPluginId()] = $condition_form;
    }
  }
  return parent::buildForm($form, $form_state);
}