lightning_core.install in Lightning Core 8.3
Same filename and directory in other branches
Contains install and update routines for Lightning.
File
lightning_core.installView source
<?php
/**
* @file
* Contains install and update routines for Lightning.
*/
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\lightning_core\ConfigHelper as Config;
use Drupal\lightning_core\UpdateManager;
/**
* Implements hook_install().
*/
function lightning_core_install() {
// Don't do anything during config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
// Record all module version numbers, including our own, in config.
$modules = array_keys(\Drupal::moduleHandler()
->getModuleList());
array_push($modules, 'lightning_core');
lightning_core_modules_installed($modules);
// Mark core view modes as internal.
lightning_core_update_8002();
}
/**
* Removed in Lightning 8.x-2.06.
*
* Formerly created the lightning_core settings object.
*
* @deprecated
*/
function lightning_core_update_8001() {
}
/**
* Marks certain node view modes as internal.
*/
function lightning_core_update_8002() {
$view_modes = EntityViewMode::loadMultiple([
'node.rss',
'node.search_index',
]);
/** @var \Drupal\Core\Entity\EntityViewModeInterface $view_mode */
foreach ($view_modes as $view_mode) {
$view_mode
->setThirdPartySetting('lightning_core', 'internal', TRUE)
->save();
}
}
/**
* Marks all entity token view modes as internal.
*/
function lightning_core_update_8003() {
if (\Drupal::moduleHandler()
->moduleExists('token')) {
lightning_core_modules_installed([
'token',
]);
}
}
/**
* Clears the entity type definition cache.
*/
function lightning_core_update_8004() {
\Drupal::entityTypeManager()
->clearCachedDefinitions();
}
/**
* Installs Lightning Roles.
*/
function lightning_core_update_8005() {
$source = \Drupal::configFactory()
->getEditable('lightning_core.settings');
$roles = $source
->get('content_roles');
// If any content role is enabled, install Lightning Roles and migrate
// the content role configuration from Lightning Core.
foreach ($roles as $role) {
if ($role['enabled']) {
\Drupal::service('module_installer')
->install([
'lightning_roles',
]);
\Drupal::configFactory()
->getEditable('lightning_roles.settings')
->set('content_roles', $roles)
->save();
break;
}
}
$source
->clear('content_roles')
->save();
}
/**
* Records all modules' semantic version numbers in config.
*/
function lightning_core_update_8006() {
$modules = Drupal::moduleHandler()
->getModuleList();
$keys = array_keys($modules);
$values = array_fill(0, count($keys), UpdateManager::VERSION_UNKNOWN);
\Drupal::configFactory()
->getEditable('lightning.versions')
->merge(array_combine($keys, $values))
->save();
}
/**
* Renames the lightning.versions config object.
*/
function lightning_core_update_8007() {
$config_factory = Drupal::configFactory();
$old = $config_factory
->getEditable('lightning.versions');
$new = $config_factory
->getEditable(UpdateManager::CONFIG_NAME);
// If the new config object didn't exist by the time this update was executed,
// just rename the old config object and call it a day.
if ($new
->isNew()) {
$config_factory
->rename($old
->getName(), $new
->getName());
}
else {
// Meekly merge the old data into the old data (i.e., the new data will take
// precedence), then delete the old config object.
$new
->setData($new
->get() + $old
->get())
->save();
$old
->delete();
}
}
/**
* Creates the Long (12-hour) date format if it does not already exist.
*/
function lightning_core_update_8008() {
Config::forModule('lightning_core')
->getEntity('date_format', 'long_12h')
->save();
}
Functions
Name | Description |
---|---|
lightning_core_install | Implements hook_install(). |
lightning_core_update_8001 | Removed in Lightning 8.x-2.06. |
lightning_core_update_8002 | Marks certain node view modes as internal. |
lightning_core_update_8003 | Marks all entity token view modes as internal. |
lightning_core_update_8004 | Clears the entity type definition cache. |
lightning_core_update_8005 | Installs Lightning Roles. |
lightning_core_update_8006 | Records all modules' semantic version numbers in config. |
lightning_core_update_8007 | Renames the lightning.versions config object. |
lightning_core_update_8008 | Creates the Long (12-hour) date format if it does not already exist. |