lightning_contact_form.install in Lightning Core 8
Same filename and directory in other branches
Contains install and update routines for Lightning Contact Form.
File
modules/lightning_contact_form/lightning_contact_form.installView source
<?php
/**
* @file
* Contains install and update routines for Lightning Contact Form.
*/
use Drupal\contact\Entity\ContactForm;
use Drupal\user\RoleInterface;
/**
* Implements hook_install().
*/
function lightning_contact_form_install() {
// Create an alias for the form if it's not already taken.
/** @var \Drupal\Core\Path\AliasStorageInterface $alias_storage */
$alias_storage = \Drupal::service('path.alias_storage');
$alias = $alias_storage
->load([
'alias' => '/contact',
]);
if (empty($alias)) {
$alias_storage
->save('/contact/sitewide', '/contact');
}
// Don't update the contact form configuration during config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
ContactForm::load('sitewide')
->setRecipients([
\Drupal::config('system.site')
->get('mail'),
])
->save();
// Grants permission to use contact form(s).
$permissions = [
'access site-wide contact form',
];
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, $permissions);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, $permissions);
}
Functions
Name | Description |
---|---|
lightning_contact_form_install | Implements hook_install(). |