lightning_core-8.x-5.3/modules/lightning_contact_form/lightning_contact_form.module
modules/lightning_contact_form/lightning_contact_form.module
<?php
/**
* @file
* Contains hook implementations for lightning_contact_form.
*/
use Drupal\contact\ContactFormInterface;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\path_alias\Entity\PathAlias;
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function lightning_contact_form_contact_form_insert(ContactFormInterface $contact_form) {
if ($contact_form->id() === 'sitewide' && InstallerKernel::installationAttempted()) {
// Create an alias for the form if it's not already taken.
$path = '/contact';
$alias = Drupal::service('path_alias.manager')->getPathByAlias($path);
if ($alias === $path) {
PathAlias::create([
'path' => '/contact/sitewide',
'alias' => $path,
])->save();
}
}
}
