language_cookie.install in Language Cookie 8
Same filename and directory in other branches
The install and update code for the language_cookie module.
File
language_cookie.installView source
<?php
/**
* @file
* The install and update code for the language_cookie module.
*
* @ingroup language_cookie
*/
use Drupal\Core\Language\LanguageInterface;
use Drupal\language_cookie\Plugin\LanguageNegotiation\LanguageNegotiationCookie;
/**
* Implements hook_install().
*/
function language_cookie_install() {
// Set up preferred language negotiation type to fetch the language from
// (the interface language, in our case).
$config = \Drupal::configFactory()
->getEditable('language_cookie.negotiation');
$config
->set('language_type', LanguageInterface::TYPE_INTERFACE);
if (\Drupal::request()
->isSecure()) {
$config
->set('secure', TRUE);
}
$config
->save();
}
/**
* Implements hook_uninstall().
*/
function language_cookie_uninstall() {
$language_types = \Drupal::languageManager()
->getLanguageTypes();
$config = \Drupal::configFactory()
->getEditable('language.types');
foreach ($language_types as $type) {
$config
->clear('negotiation.' . $type . '.enabled.' . LanguageNegotiationCookie::METHOD_ID);
}
$config
->save();
}
/**
* Set default value for the secure option.
*/
function language_cookie_update_8001(&$sandbox) {
\Drupal::configFactory()
->getEditable('language_cookie.negotiation')
->set('secure', FALSE)
->save();
}
/**
* Set default value for the http_only option.
*/
function language_cookie_update_8002(&$sandbox) {
\Drupal::configFactory()
->getEditable('language_cookie.negotiation')
->set('http_only', TRUE)
->save();
}
Functions
Name | Description |
---|---|
language_cookie_install | Implements hook_install(). |
language_cookie_uninstall | Implements hook_uninstall(). |
language_cookie_update_8001 | Set default value for the secure option. |
language_cookie_update_8002 | Set default value for the http_only option. |