easy_breadcrumb.install in Easy Breadcrumb 8
Same filename and directory in other branches
Add installation messages to help users get started and update.
File
easy_breadcrumb.installView source
<?php
/**
* @file
* Add installation messages to help users get started and update.
*/
use Drupal\easy_breadcrumb\EasyBreadcrumbConstants;
/**
* Implements hook_update().
*
* Force an update because we removed an unused service.
*/
function easy_breadcrumb_update_8001() {
// Do nothing because database updates run cache rebuild.
}
/**
* Implements hook_update().
*
* Update home_segment_keep config from integer to boolean.
*/
function easy_breadcrumb_update_8002() {
$config = \Drupal::configFactory()
->getEditable(EasyBreadcrumbConstants::MODULE_SETTINGS);
$home_segment_keep = $config
->get(EasyBreadcrumbConstants::HOME_SEGMENT_KEEP);
// If the setting is enabled, store it as TRUE.
if ($home_segment_keep === 1) {
$config
->set(EasyBreadcrumbConstants::HOME_SEGMENT_KEEP, TRUE);
}
else {
$config
->set(EasyBreadcrumbConstants::HOME_SEGMENT_KEEP, FALSE);
}
$config
->save();
}
/**
* Implements hook_update().
*
* Force an update because we updated the depedency injection which requires a
* cache clear.
*/
function easy_breadcrumb_update_8003() {
// Do nothing because database updates run cache rebuild.
}
/**
* Implements hook_update().
*
* Force a cache update because we changed service dependencies.
*/
function easy_breadcrumb_update_8004() {
// Do nothing because database updates run cache rebuild.
}
/**
* Force cache rebuild for newly added service to be picked up.
*/
function easy_breadcrumb_update_8005() {
drupal_flush_all_caches();
}
/**
* Fix configuration.
*/
function easy_breadcrumb_update_8006() {
$config = \Drupal::configFactory()
->getEditable(EasyBreadcrumbConstants::MODULE_SETTINGS);
$config
->clear('add_structured_data_jsonld')
->clear('dependencies');
// Add missing keys if not present.
$potentially_missing_keys = [
EasyBreadcrumbConstants::ADD_STRUCTURED_DATA_JSON_LD => FALSE,
EasyBreadcrumbConstants::CAPITALIZATOR_FORCED_WORDS => [],
EasyBreadcrumbConstants::INCLUDE_INVALID_PATHS => FALSE,
EasyBreadcrumbConstants::EXCLUDED_PATHS => '',
EasyBreadcrumbConstants::REPLACED_TITLES => '',
EasyBreadcrumbConstants::CUSTOM_PATHS => '',
EasyBreadcrumbConstants::TITLE_SEGMENT_AS_LINK => FALSE,
];
$data = $config
->get();
foreach ($potentially_missing_keys as $key => $default) {
if (!isset($data[$key])) {
$config
->set($key, $default);
}
}
// Fix variable types.
$config
->set(EasyBreadcrumbConstants::CAPITALIZATOR_FORCED_WORDS_FIRST_LETTER, (bool) $config
->get(EasyBreadcrumbConstants::CAPITALIZATOR_FORCED_WORDS_FIRST_LETTER));
$config
->set(EasyBreadcrumbConstants::CAPITALIZATOR_FORCED_WORDS_CASE_SENSITIVITY, (bool) $config
->get(EasyBreadcrumbConstants::CAPITALIZATOR_FORCED_WORDS_CASE_SENSITIVITY));
$config
->set(EasyBreadcrumbConstants::ADD_STRUCTURED_DATA_JSON_LD, (bool) $config
->get(EasyBreadcrumbConstants::ADD_STRUCTURED_DATA_JSON_LD));
// Change 'capitalizator_ignored_words' and 'capitalizator_forced_words' to be
// lists rather than maps.
$config
->set(EasyBreadcrumbConstants::CAPITALIZATOR_IGNORED_WORDS, array_values($config
->get(EasyBreadcrumbConstants::CAPITALIZATOR_IGNORED_WORDS) ?: []));
$config
->set(EasyBreadcrumbConstants::CAPITALIZATOR_FORCED_WORDS, array_values($config
->get(EasyBreadcrumbConstants::CAPITALIZATOR_FORCED_WORDS) ?: []));
$config
->save(TRUE);
}
/**
* Enable follow redirects.
*/
function easy_breadcrumb_update_8007() {
$config = \Drupal::configFactory()
->getEditable(EasyBreadcrumbConstants::MODULE_SETTINGS);
$config
->set(EasyBreadcrumbConstants::FOLLOW_REDIRECTS, TRUE);
$config
->save(TRUE);
}
/**
* Implements hook_install().
*
* Help users get started with the module.
*/
function easy_breadcrumb_install() {
$messenger = \Drupal::messenger();
$help_url = 'https://www.drupal.org/docs/8/modules/easy-breadcrumb';
$messenger
->addMessage("Easy Breadcrumb documentation is found in the help module or at {$help_url}.");
// Clear the cache so that the breadcrumbs appear after install.
drupal_flush_all_caches();
}
Functions
Name | Description |
---|---|
easy_breadcrumb_install | Implements hook_install(). |
easy_breadcrumb_update_8001 | Implements hook_update(). |
easy_breadcrumb_update_8002 | Implements hook_update(). |
easy_breadcrumb_update_8003 | Implements hook_update(). |
easy_breadcrumb_update_8004 | Implements hook_update(). |
easy_breadcrumb_update_8005 | Force cache rebuild for newly added service to be picked up. |
easy_breadcrumb_update_8006 | Fix configuration. |
easy_breadcrumb_update_8007 | Enable follow redirects. |