protected function EntityLegalDocumentForm::formPathSettings in Entity Legal 4.0.x
Same name and namespace in other branches
- 8.2 src/Form/EntityLegalDocumentForm.php \Drupal\entity_legal\Form\EntityLegalDocumentForm::formPathSettings()
- 3.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 270
Class
- EntityLegalDocumentForm
- Base form for contact form edit forms.
Namespace
Drupal\entity_legal\FormCode
protected function formPathSettings(array &$form) {
if (!$this->moduleHandler
->moduleExists('path')) {
return;
}
$path = [];
if (!$this->entity
->isNew()) {
$conditions = [
'source' => '/' . $this->entity
->toUrl()
->getInternalPath(),
];
$path = $this->aliasStorage
->load($conditions);
if ($path === FALSE) {
$path = [];
}
}
$path += [
'pid' => NULL,
'source' => !$this->entity
->isNew() ? '/' . $this->entity
->toUrl()
->getInternalPath() : NULL,
'alias' => '',
];
$form['path'] = [
'#type' => 'details',
'#title' => t('URL path settings'),
'#group' => 'settings',
'#attributes' => [
'class' => [
'path-form',
],
],
'#attached' => [
'library' => [
'path/drupal.path',
],
],
'#access' => $this->currentUser
->hasPermission('create url aliases') || $this->currentUser
->hasPermission('administer url aliases'),
'#weight' => 5,
'#tree' => TRUE,
'#element_validate' => [
[
'\\Drupal\\path\\Plugin\\Field\\FieldWidget\\PathWidget',
'validateFormElement',
],
],
'#parents' => [
'path',
0,
],
];
$form['path']['langcode'] = [
'#type' => 'language_select',
'#title' => t('Language'),
'#languages' => LanguageInterface::STATE_ALL,
'#default_value' => $this->entity
->language()
->getId(),
];
$form['path']['alias'] = [
'#type' => 'textfield',
'#title' => t('URL alias'),
'#default_value' => $path['alias'],
'#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' => $path['pid'],
];
$form['path']['source'] = [
'#type' => 'value',
'#value' => $path['source'],
];
}