addanother.install in Add Another 8
Same filename and directory in other branches
Contains install and update functions for addanother module.
File
addanother.installView source
<?php
/**
* @file
* Contains install and update functions for addanother module.
*/
use Drupal\node\Entity\NodeType;
/**
* Implements hook_install().
*/
function addanother_install() {
_addanother_set_content_type_configs();
}
/**
* Update existing content with default values if has not been already set.
*/
function addanother_update_8001() {
_addanother_set_content_type_configs(TRUE);
}
/**
* Set addanother options for existing content types.
*/
function _addanother_set_content_type_configs($check_existing = FALSE) {
$types = array_keys(NodeType::loadMultiple());
$configs = [
'button',
'message',
'tab',
'tab_edit',
];
/* @var \Drupal\Core\Config\Config $config_factory */
$config_factory = \Drupal::service('config.factory')
->getEditable('addanother.settings');
foreach ($types as $type) {
foreach ($configs as $config) {
if ($check_existing && !is_null($config_factory
->get("{$config}.{$type}"))) {
continue 2;
}
$config_factory
->set("{$config}.{$type}", $config_factory
->get("default_{$config}"));
}
}
$config_factory
->save();
}
Functions
Name | Description |
---|---|
addanother_install | Implements hook_install(). |
addanother_update_8001 | Update existing content with default values if has not been already set. |
_addanother_set_content_type_configs | Set addanother options for existing content types. |