You are here

public function ContentLinksForm::buildForm in General Data Protection Regulation 8.2

Same name and namespace in other branches
  1. 8 src/Form/ContentLinksForm.php \Drupal\gdpr\Form\ContentLinksForm::buildForm()
  2. 3.0.x src/Form/ContentLinksForm.php \Drupal\gdpr\Form\ContentLinksForm::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 ConfigFormBase::buildForm

File

src/Form/ContentLinksForm.php, line 97

Class

ContentLinksForm
Class ContentLinksForm.

Namespace

Drupal\gdpr\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['#tree'] = TRUE;
  $form['description'] = [
    '#markup' => $this
      ->t('Enter internal paths e.g <strong>@internal_path</strong> or full URLs e.g <strong>@full_url</strong>', [
      '@internal_path' => '/privacy-policy',
      '@full_url' => 'https://www.example.com/termsofservice.pdf',
    ]),
  ];
  $form['links'] = [
    '#type' => 'container',
  ];
  $urls = $this
    ->loadUrls();

  /** @var \Drupal\Core\Language\LanguageInterface $language */
  foreach ($this->languageManager
    ->getLanguages() as $langCode => $language) {
    $form['links'][$langCode] = [
      '#type' => 'details',
      '#title' => $language
        ->getName(),
    ];
    foreach (static::requiredContentList() as $key => $label) {
      $form['links'][$langCode][$key] = [
        '#type' => 'textfield',
        '#title' => $label,
        '#process_default_value' => FALSE,
        '#element_validate' => [
          [
            static::class,
            'validateUriElement',
          ],
        ],
        '#default_value' => isset($urls[$langCode][$key]) ? $urls[$langCode][$key] : NULL,
      ];
    }
  }
  return parent::buildForm($form, $form_state);
}