You are here

public function BrokenLinkRedirectForm::form in Broken Link 8.2

Same name and namespace in other branches
  1. 8.3 src/Form/BrokenLinkRedirectForm.php \Drupal\broken_link\Form\BrokenLinkRedirectForm::form()
  2. 8 src/Form/BrokenLinkRedirectForm.php \Drupal\broken_link\Form\BrokenLinkRedirectForm::form()

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/BrokenLinkRedirectForm.php, line 44

Class

BrokenLinkRedirectForm
Class BrokenLinkRedirectForm.

Namespace

Drupal\broken_link\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $broken_link_redirect = $this->entity;
  $pattern = '';
  if ($broken_link_redirect
    ->get('pattern')
    ->get(0)) {
    $pattern = $broken_link_redirect
      ->get('pattern')
      ->get(0)
      ->getValue()['value'];
  }
  $form['pattern'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Broken link pattern'),
    '#maxlength' => 255,
    '#default_value' => $pattern,
    '#description' => $this
      ->t("Regular expression pattern."),
    '#required' => TRUE,
  ];
  $redirect_path = '';
  if ($broken_link_redirect
    ->get('redirect_path')
    ->get(0)) {
    $redirect_path = $broken_link_redirect
      ->get('redirect_path')
      ->get(0)
      ->getValue()['value'];
  }
  $form['redirect_path'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Redirect path'),
    '#maxlength' => 2000,
    '#default_value' => $redirect_path,
    '#description' => $this
      ->t("Redirect path for broken link."),
    '#required' => TRUE,
  ];
  $enabled = TRUE;
  if ($broken_link_redirect
    ->get('enabled')
    ->get(0)) {
    $enabled = $broken_link_redirect
      ->get('enabled')
      ->get(0)
      ->getValue()['value'];
  }
  $form['enabled'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enabled'),
    '#default_value' => $enabled,
  ];
  $weight = '';
  if ($broken_link_redirect
    ->get('weight')
    ->get(0)) {
    $weight = $broken_link_redirect
      ->get('weight')
      ->get(0)
      ->getValue()['value'];
  }
  $form['weight'] = [
    '#type' => 'weight',
    '#title' => $this
      ->t('Weight'),
    '#default_value' => $weight,
    '#delta' => 10,
  ];
  return $form;
}