You are here

protected function EntityLegalDocumentForm::formPathSettings in Entity Legal 3.0.x

Same name and namespace in other branches
  1. 8.2 src/Form/EntityLegalDocumentForm.php \Drupal\entity_legal\Form\EntityLegalDocumentForm::formPathSettings()
  2. 4.0.x src/Form/EntityLegalDocumentForm.php \Drupal\entity_legal\Form\EntityLegalDocumentForm::formPathSettings()

Add path and pathauto settings to an existing legal document form.

Parameters

array $form: The Form array.

1 call to EntityLegalDocumentForm::formPathSettings()
EntityLegalDocumentForm::form in src/Form/EntityLegalDocumentForm.php
Gets the actual form array to be built.

File

src/Form/EntityLegalDocumentForm.php, line 292

Class

EntityLegalDocumentForm
Base form for contact form edit forms.

Namespace

Drupal\entity_legal\Form

Code

protected function formPathSettings(array &$form) {
  if (!$this->moduleHandler
    ->moduleExists('path')) {
    return;
  }

  /** @var \Drupal\path_alias\PathAliasInterface $alias */
  $alias = $this
    ->pathAlias($this->entity
    ->language()
    ->getId());
  $aliasSource = NULL;
  if (!$alias) {
    $aliasSource = !$this->entity
      ->isNew() ? '/' . $this->entity
      ->toUrl()
      ->getInternalPath() : NULL;
  }
  $form['path'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('URL path settings'),
    '#group' => 'settings',
    '#attributes' => [
      'class' => [
        'path-form',
      ],
    ],
    '#attached' => [
      'library' => [
        'path/drupal.path',
      ],
    ],
    '#access' => $this
      ->hasAccessToPathAliases(),
    '#weight' => 5,
    '#tree' => TRUE,
    '#element_validate' => [
      PathWidget::class,
      'validateFormElement',
    ],
    '#parents' => [
      'path',
      0,
    ],
  ];
  $form['path']['langcode'] = [
    '#type' => 'language_select',
    '#title' => $this
      ->t('Language'),
    '#languages' => LanguageInterface::STATE_ALL,
    '#default_value' => $this->entity
      ->language()
      ->getId(),
  ];
  $form['path']['alias'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('URL alias'),
    '#default_value' => $alias ? $alias
      ->getAlias() : '',
    '#maxlength' => 255,
    '#description' => $this
      ->t('The alternative URL for this content. Use a relative path. For example, enter "/about" for the about page.'),
  ];
  $form['path']['pid'] = [
    '#type' => 'value',
    '#value' => $alias ? $alias
      ->id() : NULL,
  ];
  $form['path']['source'] = [
    '#type' => 'value',
    '#value' => $alias ? $alias
      ->getPath() : $aliasSource,
  ];
}