-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontextual_aliases.module
36 lines (32 loc) · 1.24 KB
/
contextual_aliases.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
use Drupal\contextual_aliases\Entity\ContextualRedirect;
use Drupal\contextual_aliases\Form\ContextualRedirectForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\redirect\Plugin\Field\FieldWidget\RedirectSourceWidget;
/**
* Implements hook_entity_type_alter().
*/
function contextual_aliases_entity_type_alter(array &$entity_types) {
/** @var \Drupal\Core\Entity\EntityType[] $entity_types */
if (array_key_exists('redirect', $entity_types)) {
$entity_types['redirect']->setClass(ContextualRedirect::class);
$entity_types['redirect']->setFormClass('default', ContextualRedirectForm::class);
$entity_types['redirect']->setFormClass('edit', ContextualRedirectForm::class);
}
}
/**
* Collect all context options for displaying a select box.
*/
function contextual_aliases_context_options() {
return \Drupal::service('path.alias_storage')->getContextOptions();
}
/**
* Implements hook_field_widget_form_alter().
*/
function contextual_aliases_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) {
if ($context['widget'] instanceof RedirectSourceWidget) {
// Disable ajax functionality, since it doesn't know the context and
// results in false positives.
unset($element['path']['#ajax']);
}
}