You are here

public function ExternalLinkPopupForm::form in External Link Pop-up 8

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/ExternalLinkPopupForm.php, line 37

Class

ExternalLinkPopupForm
Form handler for the External Link Pop-up add and edit forms.

Namespace

Drupal\external_link_popup\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['name'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $this->entity
      ->label(),
    '#description' => $this
      ->t("Label for the External Link Pop-up."),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $this->entity
      ->id(),
    '#machine_name' => [
      'exists' => [
        $this,
        'exist',
      ],
      'source' => [
        'name',
      ],
    ],
    '#disabled' => !$this->entity
      ->isNew(),
  ];
  $form['domains'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Domains'),
    '#default_value' => $this->entity
      ->getDomains(),
    '#description' => $this
      ->t('Use base domain name without protocol or "www" prefix. Enter one domain per line.') . ' ' . $this
      ->t('"domain.com" matches all subdomains *.domain.com. Use "*" to show for all domains.'),
    '#required' => TRUE,
  ];
  $form['close'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show close icon'),
    '#default_value' => $this->entity
      ->getClose(),
  ];
  $form['title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Title'),
    '#default_value' => $this->entity
      ->getTitle(),
  ];
  $body = $this->entity
    ->getBody();
  $form['body'] = [
    '#type' => 'text_format',
    '#title' => $this
      ->t('Body text'),
    '#default_value' => $body && isset($body['value']) ? $body['value'] : '',
    '#format' => $body && isset($body['format']) ? $body['format'] : NULL,
    '#description' => $this
      ->t('You can use <em>[link:url]</em> and <em>[link:text]</em> tokens in body content.'),
    '#required' => TRUE,
  ];
  $form['labelyes'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Yes button'),
    '#default_value' => $this->entity
      ->getLabelyes(),
    '#required' => TRUE,
  ];
  $form['new_tab'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Open in new tab by default'),
    '#default_value' => $this->entity
      ->getNewTab(),
    '#description' => $this
      ->t('If a link has no target attribute it would be opened in new tab.'),
  ];
  $form['labelno'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('No button'),
    '#default_value' => $this->entity
      ->getLabelno(),
  ];
  return $form;
}