thunder.install in Thunder 8.5
Same filename and directory in other branches
Install, update and uninstall functions for the thunder installation profile.
File
thunder.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the thunder installation profile.
*/
use Drupal\Component\Utility\NestedArray;
use Drupal\update_helper\UpdateLogger;
use Drupal\Core\Entity\EntityStorageException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
/**
* Update hook dependencies.
*
* Ensure that Thunder updates come last so entity schema updates and more
* fundamental updates occur first.
*
* @return mixed
* Returns list of update hook dependencies.
*/
function thunder_update_dependencies() {
$dependencies['thunder'] = [];
// Ensure that all thunder hook_update_N functions are called after all other
// update hooks.
$list = [];
$return = [];
$updates = update_get_update_list();
// List of thunder modules with hook_update_N() functions.
$thunder_module_list = [
'thunder',
'thunder_article',
'thunder_liveblog',
'thunder_media',
'thunder_paragraphs',
'thunder_taxonomy',
'thunder_translation',
'thunder_password_policy',
'thunder_google_analytics',
'thunder_translation',
'thunder_workflow',
'thunder_ivw',
'thunder_riddle',
'thunder_search',
];
foreach ($updates as $module => $info) {
if (in_array($module, $thunder_module_list, TRUE)) {
// Build a list of thunder modules with updates to run.
$return[$module] = [];
}
else {
// Build the list of all the update hooks for thunder updates to depend
// on.
$pending = array_keys($info['pending']);
$list[$module] = array_pop($pending);
}
}
// Add the dependencies to the thunder modules with updates to run.
foreach ($return as $module => &$info) {
$info[$updates[$module]['start']] = $list;
}
return NestedArray::mergeDeepArray([
$return,
$dependencies,
], TRUE);
}
/**
* Helper function for direct use of update helper checklist service.
*
* @param string $update_id
* Identifier of update in checklist.
* @param bool $successful
* The success or failure of update.
* @param \Drupal\update_helper\UpdateLogger $updateLogger
* Used update logger service in update hook.
*/
function _thunder_mark_update_checklist($update_id, $successful, UpdateLogger $updateLogger) {
try {
/** @var \Drupal\update_helper_checklist\UpdateChecklist $update_checklist */
$update_checklist = \Drupal::service('update_helper_checklist.update_checklist');
if ($successful) {
$update_checklist
->markUpdatesSuccessful([
'thunder' => [
$update_id,
],
]);
}
else {
$update_checklist
->markUpdatesFailed([
'thunder' => [
$update_id,
],
]);
}
} catch (EntityStorageException $ee) {
$updateLogger
->warning(t('Unable to mark update in checklist.'));
} catch (ServiceNotFoundException $se) {
// If service is not available, we will just ignore it.
}
}
/**
* Implements hook_requirements().
*/
function thunder_requirements($phase) {
if ($phase !== 'update') {
return [];
}
$requirements = [];
$thunder_schema = drupal_get_installed_schema_version('thunder');
if ($thunder_schema > 8000 && $thunder_schema < 8138) {
$requirements['thunder'] = [
'title' => t('Thunder'),
'description' => t('You need to update to the latest version of Thunder 2 before switching to Thunder 3.'),
'severity' => REQUIREMENT_ERROR,
];
}
return $requirements;
}
/**
* OBSOLETE - Add missing region key to field groups in form display settings.
*/
function thunder_update_8301() {
}
/**
* Change replace button to remove button on image paragraph form.
*/
function thunder_update_8302() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('thunder', 'thunder_update_8302');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Installs the autosave_form module.
*/
function thunder_update_8303() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('thunder', 'thunder_update_8303');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Installs the autofill module.
*/
function thunder_update_8304() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('thunder', 'thunder_update_8304');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Disable paragraphs drag & drop action button.
*/
function thunder_update_8305() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('thunder', 'thunder_update_8305');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Adjust order of paragraph types in add dialog to be consistent.
*/
function thunder_update_8306() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('thunder', 'thunder_update_8306');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Change entity browser widget in paragraphs integration.
*/
function thunder_update_8307() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
$configFactory = \Drupal::configFactory();
// Modify paragraph form displays using inline_entity_form.
$entityFormDisplayIds = Drupal::entityQuery('entity_form_display')
->condition('targetEntityType', 'paragraph')
->execute();
try {
$entityFormDisplayStorage = \Drupal::entityTypeManager()
->getStorage('entity_form_display');
foreach ($entityFormDisplayIds as $entityFormDisplayId) {
/** @var \Drupal\Core\Entity\EntityDisplayBase $entityFormDisplay */
$entityFormDisplay = $entityFormDisplayStorage
->load($entityFormDisplayId);
foreach ($entityFormDisplay
->getComponents() as $name => $options) {
// Modify only entity_browser_entity_reference fields with field widget
// display 'inline_entity_form'.
if ($options['type'] !== 'entity_browser_entity_reference' || $options['settings']['field_widget_display'] !== 'inline_entity_form') {
continue;
}
unset($options['settings']['field_widget_display_settings']['form_mode']);
$options['settings']['field_widget_display'] = 'rendered_entity';
$options['settings']['field_widget_edit'] = TRUE;
$options['settings']['field_widget_display_settings']['view_mode'] = 'thumbnail';
$entityFormDisplay
->setComponent($name, $options)
->save();
// These kind of fields cannot be required.
$field_id = 'field.field.' . $entityFormDisplay
->getTargetEntityTypeId() . '.' . $entityFormDisplay
->get('bundle') . '.' . $name;
$field = $configFactory
->getEditable($field_id);
$field
->set('required', FALSE)
->save();
$updateHelper
->logger()
->info('Converted field_widget_display from inline_entity form to rendered_entity for field ' . $name . ' in the ' . $entityFormDisplay
->get('bundle') . ' paragraph ');
}
}
} catch (\Exception $e) {
$updateHelper
->logger()
->error($e
->getMessage());
}
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Let paragraph preview image style use the focal point.
*/
function thunder_update_8308() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('thunder', 'thunder_update_8308');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Install optional modules for users that already use them.
*/
function thunder_update_8309() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
$modules_to_install = [];
if (\Drupal::moduleHandler()
->moduleExists('content_moderation')) {
/** @var \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller */
$moduleInstaller = \Drupal::service('module_installer');
$moduleInstaller
->install([
'scheduler_content_moderation_integration',
'config_update',
]);
$modules_to_install[] = 'thunder_workflow';
}
if (\Drupal::moduleHandler()
->moduleExists('ivw_integration')) {
$modules_to_install[] = 'thunder_ivw';
}
if (\Drupal::moduleHandler()
->moduleExists('google_analytics')) {
$modules_to_install[] = 'thunder_google_analytics';
}
if (\Drupal::moduleHandler()
->moduleExists('content_translation')) {
$modules_to_install[] = 'thunder_translation';
}
$version = \Drupal::CORE_MINIMUM_SCHEMA_VERSION;
$extension_config = \Drupal::configFactory()
->getEditable('core.extension');
foreach ($modules_to_install as $module) {
$extension_config
->set("module.{$module}", 0);
// Set the schema version to the number of the last update provided by
// the module, or the minimum core schema version.
$versions = drupal_get_schema_versions($module);
if ($versions) {
$version = max(max($versions), $version);
}
drupal_set_installed_schema_version($module, $version);
/** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
$post_update_registry = \Drupal::service('update.post_update_registry');
$post_update_registry
->filterOutInvokedUpdatesByModule($module);
}
$extension_config
->set('module', module_config_sort($extension_config
->get('module')))
->save(TRUE);
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Prepare the content view for the config selector.
*/
function thunder_update_8310() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('thunder', 'thunder_update_8310');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Enable bulk editing for media images.
*/
function thunder_update_8311() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('thunder', 'thunder_update_8311');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
Functions
Name | Description |
---|---|
thunder_requirements | Implements hook_requirements(). |
thunder_update_8301 | OBSOLETE - Add missing region key to field groups in form display settings. |
thunder_update_8302 | Change replace button to remove button on image paragraph form. |
thunder_update_8303 | Installs the autosave_form module. |
thunder_update_8304 | Installs the autofill module. |
thunder_update_8305 | Disable paragraphs drag & drop action button. |
thunder_update_8306 | Adjust order of paragraph types in add dialog to be consistent. |
thunder_update_8307 | Change entity browser widget in paragraphs integration. |
thunder_update_8308 | Let paragraph preview image style use the focal point. |
thunder_update_8309 | Install optional modules for users that already use them. |
thunder_update_8310 | Prepare the content view for the config selector. |
thunder_update_8311 | Enable bulk editing for media images. |
thunder_update_dependencies | Update hook dependencies. |
_thunder_mark_update_checklist | Helper function for direct use of update helper checklist service. |