thunder_media.install in Thunder 8.2
Contains.
File
modules/thunder_media/thunder_media.installView source
<?php
/**
* @file
* Contains.
*/
use Drupal\Component\Utility\DiffArray;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\TempStore\TempStoreException;
use Drupal\views\Entity\View;
use Drupal\entity_browser\Entity\EntityBrowser;
use Drupal\user\Entity\Role;
use Drupal\field\Entity\FieldConfig;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
/**
* Install the thunder media integration.
*/
function thunder_media_install() {
// Disable default media view, because we have our own.
if ($media_view = View::load('media')) {
$media_view
->setStatus(FALSE)
->save();
}
if ($thunder_media_view = View::load('thunder_media')) {
$thunder_media_view
->setStatus(TRUE)
->save();
}
}
/**
* Uninstall the thunder media integration.
*/
function thunder_media_uninstall() {
// Enable default media view.
if ($thunder_media_view = View::load('thunder_media')) {
$thunder_media_view
->setStatus(FALSE)
->save();
}
if ($media_view = View::load('media')) {
$media_view
->setStatus(TRUE)
->save();
}
}
/**
* Update hook dependencies.
*
* 1. Dependency on Thunder Updater module.
*
* @return mixed
* Returns list of update hook dependencies.
*/
function thunder_media_update_dependencies() {
$installThunderUpdaterHook = [
'thunder' => 8103,
];
$dependencies['thunder_media'] = [
8002 => $installThunderUpdaterHook,
8003 => $installThunderUpdaterHook,
8004 => $installThunderUpdaterHook,
8005 => $installThunderUpdaterHook,
8006 => $installThunderUpdaterHook,
8007 => $installThunderUpdaterHook,
8008 => $installThunderUpdaterHook,
8009 => $installThunderUpdaterHook,
8010 => $installThunderUpdaterHook,
8011 => $installThunderUpdaterHook,
8012 => $installThunderUpdaterHook,
8013 => $installThunderUpdaterHook,
8101 => $installThunderUpdaterHook,
8102 => $installThunderUpdaterHook,
8106 => [
'thunder' => 8114,
],
];
return $dependencies;
}
/**
* Support for legacy configuration update behaviour.
*
* With switching to "update_helper" module, API for direct configuration update
* is removed. That's why we have to use helper function.
*
* @param string $config_name
* Configuration name that should be updated.
* @param array $configuration
* Configuration array to update.
* @param array $expected_configuration
* Only if current config is same like old config we are updating.
* @param array $delete_keys
* List of parent keys to remove. @see NestedArray::unsetValue()
*
* @return bool
* Returns TRUE if update of configuration was successful.
*
* @see \Drupal\update_helper\Updater::updateConfig()
*/
function _thunder_media_update_config($config_name, array $configuration, array $expected_configuration = [], array $delete_keys = []) {
$config_factory = \Drupal::configFactory();
$config = $config_factory
->getEditable($config_name);
$config_data = $config
->get();
// Check that configuration exists before executing update.
if (empty($config_data)) {
return FALSE;
}
// Check if configuration is already in new state.
$merged_data = NestedArray::mergeDeep($expected_configuration, $configuration);
if (empty(DiffArray::diffAssocRecursive($merged_data, $config_data))) {
return TRUE;
}
if (!empty($expected_configuration) && DiffArray::diffAssocRecursive($expected_configuration, $config_data)) {
return FALSE;
}
// Delete configuration keys from config.
if (!empty($delete_keys)) {
foreach ($delete_keys as $key_path) {
NestedArray::unsetValue($config_data, $key_path);
}
}
$config
->setData(NestedArray::mergeDeep($config_data, $configuration));
$config
->save();
return TRUE;
}
/**
* Update entity browser configuration.
*
* @param string $browser
* Id of the entity browser.
* @param array $configuration
* Configuration array to update.
* @param array $oldConfiguration
* Only if current config is same like old config we are updating.
*
* @return bool
* Indicates if config was updated or not.
*/
function _thunder_media_update_entity_browser_config($browser, array $configuration, array $oldConfiguration = []) {
if (!_thunder_media_update_config('entity_browser.browser.' . $browser, $configuration, $oldConfiguration)) {
return FALSE;
}
/** @var \Drupal\Core\TempStore\SharedTempStoreFactory $temp_store_factory */
$temp_store_factory = \Drupal::service('tempstore.shared');
$entity_browser_config = $temp_store_factory
->get('entity_browser.config');
// Entity browser form uses ctools wizard form and if some has opened that
// form status is saved in temp storage and we want to update that status too.
$storage = $entity_browser_config
->get($browser);
if (empty($storage)) {
return TRUE;
}
foreach ($configuration as $key => $value) {
$part = $storage['entity_browser']
->getPluginCollections()[$key];
$part
->setConfiguration(NestedArray::mergeDeep($part
->getConfiguration(), $value));
}
try {
$entity_browser_config
->set($browser, $storage);
} catch (TempStoreException $e) {
return FALSE;
}
return TRUE;
}
/**
* Rename config object.
*/
function thunder_media_update_8001() {
\Drupal::configFactory()
->getEditable('thunder_media.settings')
->setData(\Drupal::configFactory()
->get('thunder_media.configuration')
->getRawData())
->save();
}
/**
* Change media_thumbnail image style.
*/
function thunder_media_update_8002() {
// List of configurations that should be checked for existence.
$expectedConfig['effects']['8a41a5b5-469d-4918-879e-460f26e08700']['data']['width'] = 241;
$expectedConfig['effects']['8a41a5b5-469d-4918-879e-460f26e08700']['data']['height'] = 138;
$expectedConfig['effects']['8a41a5b5-469d-4918-879e-460f26e08700']['id'] = 'focal_point_scale_and_crop';
// New configuration that should be applied.
$newConfig['effects']['8a41a5b5-469d-4918-879e-460f26e08700']['data']['width'] = 182;
$newConfig['effects']['8a41a5b5-469d-4918-879e-460f26e08700']['data']['height'] = 104;
_thunder_media_update_config('image.style.media_thumbnail', $newConfig, $expectedConfig);
}
/**
* Add entity browser view sorting.
*/
function thunder_media_update_8003() {
$sorting = [
'created' => [
'id' => 'created',
'table' => 'media_field_data',
'field' => 'created',
'relationship' => 'none',
'group_type' => 'group',
'admin_label' => '',
'order' => 'DESC',
'exposed' => FALSE,
'expose' => [
'label' => '',
],
'granularity' => 'second',
'entity_type' => 'media',
'entity_field' => 'created',
'plugin_id' => 'date',
],
];
$browsers = [
'image_browser',
'media_browser',
'gallery_browser',
];
foreach ($browsers as $browser) {
/** @var \Drupal\views\Entity\View $view */
$view = View::load($browser);
if (!empty($view) && empty($view
->getDisplay('default')['display_options']['sorts'])) {
$view
->getDisplay('default')['display_options']['sorts'] = $sorting;
$view
->save();
}
}
}
/**
* Enable auto_open for gallery browser.
*/
function thunder_media_update_8004() {
// List of configurations that should be checked for existence. We are trying
// to ensure, that active display settings are provided by our configuration.
$expectedConfig['display_configuration']['width'] = '1070';
$expectedConfig['display_configuration']['height'] = '';
$expectedConfig['display_configuration']['link_text'] = 'Select entities';
// This option is introduced with new version of entity browser module, so
// it didn't exist before, because of that it's not possible to check
// existing configuration value for this property.
$configsToUpdate['display_configuration']['auto_open'] = TRUE;
_thunder_media_update_entity_browser_config('gallery_browser', $configsToUpdate, $expectedConfig);
}
/**
* Update dropzonejs widget file extension filtering for images.
*/
function thunder_media_update_8005() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updateLogger = $updater
->logger();
// List of expected configuration for listed entity browsers.
$expectedConfig['multiple_image_browser']['widgets']['89532aea-140d-4b9e-96f4-2aa489c095cb']['settings']['extensions'] = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp';
$expectedConfig['image_browser']['widgets']['e6bbb585-adb6-4023-aece-e73d893491c9']['settings']['extensions'] = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp';
$expectedConfig['media_browser']['widgets']['ec1759ab-e969-4448-a9db-d3a70e123326']['settings']['extensions'] = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp';
// New configuration for entity browsers that should be applied.
$newConfig['multiple_image_browser']['widgets']['89532aea-140d-4b9e-96f4-2aa489c095cb']['settings']['extensions'] = 'png gif jpg jpeg';
$newConfig['image_browser']['widgets']['e6bbb585-adb6-4023-aece-e73d893491c9']['settings']['extensions'] = 'png gif jpg jpeg';
$newConfig['media_browser']['widgets']['ec1759ab-e969-4448-a9db-d3a70e123326']['settings']['extensions'] = 'png gif jpg jpeg';
foreach ($newConfig as $browser => $configuration) {
if (_thunder_media_update_entity_browser_config($browser, $configuration, $expectedConfig[$browser])) {
$message = t('Image extensions filtering for "@configName" has been updated.', [
'@configName' => 'entity_browser.browser.' . $browser,
]);
$updateLogger
->info($message);
}
else {
$message = t('Image extensions filtering for "@configName" was not updated. Please ensure that file extensions are set to "@newExtensions" for upload image widget.', [
'@configName' => 'entity_browser.browser.' . $browser,
'@newExtensions' => 'png gif jpg jpeg',
]);
$updateLogger
->warning($message);
}
}
return $updateLogger
->output();
}
/**
* Enable auto_select on multiple_image_browser.
*/
function thunder_media_update_8006() {
// Ensure that defined widgets exist, in other case wrong configuration could
// be generated. It's not possible to check for existing value of updated
// configuration, because it's introduced with new entity browser
// functionality for auto select of entities in view and dropzonejs widgets.
// We are checking only that widgets previously provided by configuration are
// still exist and only they will be updated.
$expectedConfig['widgets']['7d7f8f45-f628-48a3-84a8-c962c73f39e8']['uuid'] = '7d7f8f45-f628-48a3-84a8-c962c73f39e8';
$expectedConfig['widgets']['89532aea-140d-4b9e-96f4-2aa489c095cb']['uuid'] = '89532aea-140d-4b9e-96f4-2aa489c095cb';
// New configuration that should be applied.
$newConfig['widgets']['7d7f8f45-f628-48a3-84a8-c962c73f39e8']['settings']['auto_select'] = TRUE;
$newConfig['widgets']['89532aea-140d-4b9e-96f4-2aa489c095cb']['settings']['auto_select'] = TRUE;
_thunder_media_update_entity_browser_config('multiple_image_browser', $newConfig, $expectedConfig);
}
/**
* Make instagrams responsive.
*/
function thunder_media_update_8007() {
// List of configurations that should be checked for existence.
$expectedConfig['content']['field_url']['settings']['width'] = 480;
$expectedConfig['content']['field_url']['settings']['height'] = 640;
// New configuration that should be applied.
$newConfig['content']['field_url']['settings']['width'] = NULL;
$newConfig['content']['field_url']['settings']['height'] = NULL;
_thunder_media_update_config('core.entity_view_display.media.instagram.default', $newConfig, $expectedConfig);
}
/**
* New image style for entity browser.
*/
function thunder_media_update_8008() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updateLogger = $updater
->logger();
\Drupal::service('module_installer')
->install([
'config_update',
]);
// List of expected configuration for listed entity browser views.
$expectedConfig['image_browser']['display']['default']['display_options']['fields']['thumbnail__target_id']['settings']['image_style'] = 'media_thumbnail';
$expectedConfig['media_browser']['display']['default']['display_options']['fields']['thumbnail__target_id']['settings']['image_style'] = 'media_thumbnail';
$expectedConfig['gallery_browser']['display']['default']['display_options']['fields']['thumbnail__target_id']['settings']['image_style'] = 'media_thumbnail';
// New configuration for entity browser views that should be applied.
$newConfig['image_browser']['display']['default']['display_options']['fields']['thumbnail__target_id']['settings']['image_style'] = 'entity_browser_thumbnail';
$newConfig['media_browser']['display']['default']['display_options']['fields']['thumbnail__target_id']['settings']['image_style'] = 'entity_browser_thumbnail';
$newConfig['gallery_browser']['display']['default']['display_options']['fields']['thumbnail__target_id']['settings']['image_style'] = 'entity_browser_thumbnail';
try {
\Drupal::service('config_update.config_update')
->import('image_style', 'entity_browser_thumbnail');
$message = t('New image style entity_browser_thumbnail created.');
$updateLogger
->info($message);
foreach ($newConfig as $view => $configuration) {
if (_thunder_media_update_config('views.view.' . $view, $configuration, $expectedConfig[$view])) {
$message = t('View "@view" is now using image style entity_browser_thumbnail.', [
'@view' => $view,
]);
$updateLogger
->info($message);
}
}
} catch (\Exception $e) {
$message = t('Image style entity_browser_thumbnail was not created.');
$updateLogger
->warning($message);
}
return $updateLogger
->output();
}
/**
* Set required fields for Image and Video bundles.
*/
function thunder_media_update_8009() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updateLogger = $updater
->logger();
// List of expected configurations that should be checked.
$expectedConfig['field.field.media.image.field_image']['required'] = FALSE;
$expectedConfig['field.field.media.video.field_media_video_embed_field']['required'] = FALSE;
// Config for required Video and Image media fields.
$configsToUpdate['field.field.media.image.field_image']['required'] = TRUE;
$configsToUpdate['field.field.media.video.field_media_video_embed_field']['required'] = TRUE;
// Check that gallery paragraph uses complex widget.
foreach ($configsToUpdate as $configName => $newConfig) {
if (!_thunder_media_update_config($configName, $newConfig, $expectedConfig[$configName])) {
$updateLogger
->warning(t('Unable to set field "@configName" as required.', [
'@configName' => $configName,
]));
}
}
return $updateLogger
->output();
}
/**
* Activate support for responsive images with Blazy.
*/
function thunder_media_update_8010() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updateLogger = $updater
->logger();
// Import image styles.
\Drupal::service('module_installer')
->install([
'config_update',
]);
try {
$configUpdater = \Drupal::service('config_update.config_update');
$configUpdater
->import('responsive_image_style', 'media_image');
$configUpdater
->import('image_style', 'media_image_tablet');
$configUpdater
->import('image_style', 'media_image_mobile');
$configUpdater
->import('slick', 'thunder_gallery');
} catch (\Exception $e) {
$message = t('Responsive image styles was not created.');
$updateLogger
->warning($message);
}
// Expected settings for blazy module.
$expectedBlazySettings['responsive_image'] = FALSE;
// New settings for blazy module.
$newBlazySettings['responsive_image'] = TRUE;
if (\Drupal::moduleHandler()
->moduleExists('blazy') && \Drupal::moduleHandler()
->moduleExists('responsive_image') && _thunder_media_update_config('blazy.settings', $newBlazySettings, $expectedBlazySettings)) {
$updateLogger
->info('The support for responsive images was activated in the Blazy settings.');
}
// Expected configurations for required Video and Image media fields.
$expectedConfigs['core.entity_view_display.media.image.default']['content']['field_image']['settings']['image_style'] = 'media_image';
$expectedConfigs['core.entity_view_display.media.image.default']['content']['field_image']['settings']['responsive_image_style'] = '';
$expectedConfigs['core.entity_view_display.media.gallery.default']['content']['field_media_images']['settings']['optionset'] = 'default';
$expectedConfigs['core.entity_view_display.media.image.slick']['content']['field_image']['settings']['image_style'] = 'gallery';
$expectedConfigs['core.entity_view_display.media.image.slick']['content']['field_image']['settings']['responsive_image_style'] = '';
$expectedConfigs['image.style.media_image']['effects']['21ef239e-0d92-4fcc-84fc-17f4da42ae2f']['data']['width'] = 925;
$expectedConfigs['image.style.media_image']['effects']['21ef239e-0d92-4fcc-84fc-17f4da42ae2f']['data']['height'] = 520;
// Config for required Video and Image media fields.
$newConfigs['core.entity_view_display.media.image.default']['content']['field_image']['settings']['image_style'] = '';
$newConfigs['core.entity_view_display.media.image.default']['content']['field_image']['settings']['responsive_image_style'] = 'media_image';
$newConfigs['core.entity_view_display.media.gallery.default']['content']['field_media_images']['settings']['optionset'] = 'thunder_gallery';
$newConfigs['core.entity_view_display.media.image.slick']['content']['field_image']['settings']['image_style'] = '';
$newConfigs['core.entity_view_display.media.image.slick']['content']['field_image']['settings']['responsive_image_style'] = 'media_image';
$newConfigs['image.style.media_image']['effects']['21ef239e-0d92-4fcc-84fc-17f4da42ae2f']['data']['width'] = 938;
$newConfigs['image.style.media_image']['effects']['21ef239e-0d92-4fcc-84fc-17f4da42ae2f']['data']['height'] = 527;
foreach ($newConfigs as $configName => $newConfig) {
if (!_thunder_media_update_config($configName, $newConfig, $expectedConfigs[$configName])) {
$updateLogger
->warning(t('Unable to update configuration for "@configName".', [
'@configName' => $configName,
]));
}
}
return $updateLogger
->output();
}
/**
* Remove "auto_select" from EB widget config, for those who don't support it.
*/
function thunder_media_update_8011() {
/** @var \Drupal\entity_browser\Entity\EntityBrowser[] $browsers */
$browsers = EntityBrowser::loadMultiple();
foreach ($browsers as $browser) {
$config = Drupal::configFactory()
->getEditable('entity_browser.browser.' . $browser
->getConfigTarget());
foreach ($browser
->getWidgets() as $id => $widget) {
if (!$widget
->getPluginDefinition()['auto_select']) {
$config
->clear('widgets.' . $id . '.settings.auto_select');
}
}
$config
->save();
}
}
/**
* Change preview image style for image media bundle to "medium" image style.
*/
function thunder_media_update_8012() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updateLogger = $updater
->logger();
// List of configurations that should be checked for existence.
$expectedConfig['content']['field_image']['settings']['preview_image_style'] = 'thumbnail';
// New configuration that should be applied.
$newConfig['content']['field_image']['settings']['preview_image_style'] = 'medium';
// Execute update of config with additional validation of existing config.
$updateExecuted = _thunder_media_update_config('core.entity_form_display.media.image.default', $newConfig, $expectedConfig);
// Log result of update.
if ($updateExecuted) {
$updateLogger
->info(t('Preview image style for image media bundle is successfully updated.'));
}
else {
$updateLogger
->warning(t('Unable to change preview image style for image media bundle.'));
}
// Output collected update log for UI update script.
return $updateLogger
->output();
}
/**
* Import slick media display view configuration.
*/
function thunder_media_update_8013() {
/** @var \Drupal\update_helper\UpdateLogger $updateLogger */
$updateLogger = \Drupal::service('update_helper.logger');
/** @var \Drupal\Core\Config\StorageInterface $configStorage */
$configStorage = \Drupal::service('config.storage');
if ($configStorage
->exists('core.entity_view_display.media.image.slick')) {
$updateLogger
->info(t('Configuration already exists.'));
}
else {
// Enable "config_update" module.
\Drupal::service('module_installer')
->install([
'config_update',
]);
/** @var \Drupal\config_update\ConfigRevertInterface $configUpdater */
$configUpdater = \Drupal::service('config_update.config_update');
try {
$configUpdater
->import('entity_view_display', 'media.image.slick');
$updateLogger
->info(t('Configuration successfully imported.'));
} catch (\Exception $e) {
$updateLogger
->warning(t('Unable to import configuration: core.entity_view_display.media.image.slick.yml.'));
}
}
// Output collected update log.
return $updateLogger
->output();
}
/**
* Remove "Language" filter and add descriptions from media browsers.
*/
function thunder_media_update_8101() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updateLogger = $updater
->logger();
// Perform removal of language filters from relevant views.
$successfulUpdate = TRUE;
$viewIds = [
'image_browser',
'media_browser',
];
foreach ($viewIds as $viewId) {
/** @var \Drupal\views\Entity\View $view */
$view = View::load($viewId);
if (!empty($view) && !empty($view
->getDisplay('default')['display_options']['filters']['langcode'])) {
unset($view
->getDisplay('default')['display_options']['filters']['langcode']);
try {
$view
->save();
$updateLogger
->info(t('Language filter for media browser view "@view_id" is removed.', [
'@view_id' => $viewId,
]));
} catch (EntityStorageException $storageException) {
$successfulUpdate = FALSE;
$updateLogger
->warning(t('Unable to save changes for view: @view_id.', [
'@view_id' => $viewId,
]));
}
}
else {
$successfulUpdate = FALSE;
$updateLogger
->warning(t('Unable to remove Language filter for media browser view: @view_id.', [
'@view_id' => $viewId,
]));
}
}
// Update names and descriptions for Image view.
$expectedImageViewConfig['display']['default']['display_options']['filters']['status']['group_info']['description'] = '';
$expectedImageViewConfig['display']['default']['display_options']['filters']['status']['group_info']['default_group'] = 'All';
$expectedImageViewConfig['display']['default']['display_options']['filters']['name']['expose']['label'] = 'Media name';
$expectedImageViewConfig['display']['default']['display_options']['filters']['name']['expose']['description'] = '';
$newImageViewConfig['display']['default']['display_options']['filters']['status']['group_info']['description'] = 'Filter by status';
$newImageViewConfig['display']['default']['display_options']['filters']['status']['group_info']['default_group'] = '1';
$newImageViewConfig['display']['default']['display_options']['filters']['name']['expose']['label'] = 'Image name';
$newImageViewConfig['display']['default']['display_options']['filters']['name']['expose']['description'] = 'Filter by name';
if (_thunder_media_update_config('views.view.image_browser', $newImageViewConfig, $expectedImageViewConfig)) {
$updateLogger
->info(t('Entity browser image view filter descriptions and names are updated.'));
}
else {
$successfulUpdate = FALSE;
$updateLogger
->warning(t('Unable to change entity browser image view filter descriptions and names.'));
}
// If update is successful for all views, then check entry in checklist.
if (!$successfulUpdate) {
$updateLogger
->warning(t('Unable to remove language filters from views. Please perform this process manually.'));
}
try {
/** @var \Drupal\update_helper_checklist\UpdateChecklist $updateChecklist */
$updateChecklist = \Drupal::service('update_helper_checklist.update_checklist');
if ($successfulUpdate) {
$updateChecklist
->markUpdatesSuccessful([
'thunder' => [
'v1_1__remove_entity_browser_language_filter',
],
]);
}
else {
$updateChecklist
->markUpdatesFailed([
'thunder' => [
'v1_1__remove_entity_browser_language_filter',
],
]);
}
} 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.
}
// Output log result depending on channel used for update execution.
return $updateLogger
->output();
}
/**
* Introduce image and video paragraph.
*/
function thunder_media_update_8102() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updateLogger = $updater
->logger();
\Drupal::service('module_installer')
->install([
'config_update',
]);
$configUpdater = \Drupal::service('config_update.config_update');
$imports = [
'paragraphs_type' => [
'image',
'video',
],
'field_storage_config' => [
'paragraph.field_image',
'paragraph.field_video',
],
'field_config' => [
'paragraph.image.field_image',
'paragraph.video.field_video',
],
'view' => [
'video_browser',
],
'system.simple' => [
'entity_browser.browser.video_browser',
],
'entity_form_display' => [
'paragraph.video.default',
'paragraph.image.default',
],
'entity_view_display' => [
'paragraph.video.default',
'paragraph.image.default',
'paragraph.image.preview',
'paragraph.video.preview',
],
];
$successfulUpdate = TRUE;
foreach ($imports as $type => $entities) {
foreach ($entities as $entity) {
try {
$configUpdater
->import($type, $entity);
$updateLogger
->info(t('Successfully imported configuration: @type -> @entity', [
'@type' => $type,
'@entity' => $entity,
]));
} catch (\Exception $e) {
$successfulUpdate = FALSE;
$updateLogger
->warning(t('Unable to import config: @type -> @entity', [
'@type' => $type,
'@entity' => $entity,
]));
}
}
}
if ($successfulUpdate) {
/** @var \Drupal\user\Entity\Role[] $roles */
$roles = Role::loadMultiple([
'editor',
'seo',
]);
foreach ($roles as $role) {
try {
$role
->grantPermission('access video_browser entity browser pages');
$role
->save();
$updateLogger
->info(t('Permission for accessing video browser is granted for @user_role user role.', [
'@user_role' => $role
->id(),
]));
} catch (EntityStorageException $storageException) {
$successfulUpdate = FALSE;
$updateLogger
->warning(t('Unable to change permissions for @user_role user role.', [
'@user_role' => $role
->id(),
]));
}
}
$fieldConfigs = [
'node.article.field_paragraphs',
'taxonomy_term.channel.field_paragraphs',
'taxonomy_term.tags.field_paragraphs',
];
foreach ($fieldConfigs as $fieldConfig) {
/** @var \Drupal\field\Entity\FieldConfig $field */
$field = FieldConfig::load($fieldConfig);
if ($field) {
$settings = $field
->getSetting('handler_settings');
$settings['target_bundles']['image'] = 'image';
$settings['target_bundles']['video'] = 'video';
$settings['target_bundles_drag_drop']['image'] = [
'enabled' => TRUE,
'weight' => 10,
];
$settings['target_bundles_drag_drop']['video'] = [
'enabled' => TRUE,
'weight' => 10,
];
try {
$field
->setSetting('handler_settings', $settings);
$field
->save();
$updateLogger
->info(t('Field @field_id successfully changed.', [
'@field_id' => $field
->id(),
]));
} catch (EntityStorageException $storageException) {
$successfulUpdate = FALSE;
$updateLogger
->warning(t('Unable to save changes for @field_id field.', [
'@field_id' => $field
->id(),
]));
}
}
else {
$successfulUpdate = FALSE;
$updateLogger
->warning(t('Unable to change field config for @fieldConfig.', [
'@fieldConfig' => $fieldConfig,
]));
}
}
// Update gallery and image entity browser settings.
$expectedConfigs['multiple_image_browser']['display_configuration']['link_text'] = 'Select entities';
$expectedConfigs['multiple_image_browser']['widgets']['7d7f8f45-f628-48a3-84a8-c962c73f39e8']['settings']['submit_text'] = 'Select entities';
$expectedConfigs['image_browser']['display_configuration']['link_text'] = 'Select entities';
$expectedConfigs['image_browser']['widgets']['f09e2255-6bd8-4301-ba02-1d446f7fca70']['settings']['submit_text'] = 'Select entities';
// New configuration for entity browsers that should be applied.
$newConfigs['multiple_image_browser']['display_configuration']['link_text'] = 'Select images';
$newConfigs['multiple_image_browser']['widgets']['7d7f8f45-f628-48a3-84a8-c962c73f39e8']['settings']['submit_text'] = 'Select images';
$newConfigs['image_browser']['display_configuration']['link_text'] = 'Select image';
$newConfigs['image_browser']['widgets']['f09e2255-6bd8-4301-ba02-1d446f7fca70']['settings']['submit_text'] = 'Select image';
foreach ($newConfigs as $browserId => $newConfig) {
if (_thunder_media_update_entity_browser_config($browserId, $newConfig, $expectedConfigs[$browserId])) {
$updateLogger
->info(t('Text for @browser_id entity browser is adjusted.', [
'@browser_id' => $browserId,
]));
}
else {
$successfulUpdate = FALSE;
$updateLogger
->warning(t('Unable to update @browser_id entity browser configuration.', [
'@browser_id' => $browserId,
]));
}
}
}
try {
/** @var \Drupal\update_helper_checklist\UpdateChecklist $updateChecklist */
$updateChecklist = \Drupal::service('update_helper_checklist.update_checklist');
if ($successfulUpdate) {
$updateChecklist
->markUpdatesSuccessful([
'thunder' => [
'v1_1__image_video_paragraph',
],
], FALSE);
}
else {
$updateChecklist
->markUpdatesFailed([
'thunder' => [
'v1_1__image_video_paragraph',
],
]);
}
} 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.
}
// Output log result depending on channel used for update execution.
return $updateLogger
->output();
}
/**
* Adjust instagrams preview in backend.
*/
function thunder_media_update_8103() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updateLogger = $updater
->logger();
// List of configurations that should be checked for existence.
$expectedConfig['hidden']['thumbnail'] = TRUE;
$expectedConfig['content']['field_url'] = [
'type' => 'instagram_embed',
'weight' => 0,
'label' => 'hidden',
'settings' => [
'width' => 241,
'height' => 313,
],
'third_party_settings' => [],
];
// New configuration that should be applied.
$newConfig['content']['thumbnail'] = [
'type' => 'image',
'weight' => 0,
'region' => 'content',
'label' => 'hidden',
'settings' => [
'image_style' => 'media_thumbnail',
'image_link' => '',
],
'third_party_settings' => [],
];
$successfulUpdate = TRUE;
if (_thunder_media_update_config('core.entity_view_display.media.instagram.thumbnail', $newConfig, $expectedConfig)) {
$display = EntityViewDisplay::load('media.instagram.thumbnail');
$display
->removeComponent('field_url')
->save();
$updateLogger
->info(t('Configuration is successfully changed for instagram thumbnail.'));
}
else {
$updateLogger
->warning(t('Unable to adjust core.entity_view_display.media.instagram.thumbnail config'));
$successfulUpdate = FALSE;
}
try {
/** @var \Drupal\update_helper_checklist\UpdateChecklist $updateChecklist */
$updateChecklist = \Drupal::service('update_helper_checklist.update_checklist');
if ($successfulUpdate) {
$updateChecklist
->markUpdatesSuccessful([
'thunder' => [
'v1_1__instagram_edit_preview',
],
]);
}
else {
$updateChecklist
->markUpdatesFailed([
'thunder' => [
'v1_1__instagram_edit_preview',
],
]);
}
} 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.
}
// Output log result depending on channel used for update execution.
return $updateLogger
->output();
}
/**
* Increase number of items per page to 24 in entity browser.
*/
function thunder_media_update_8104() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updateLogger = $updater
->logger();
// List of configurations that should be checked for existence.
$expectedConfig['display']['default']['display_options']['pager']['options']['items_per_page'] = 20;
// New configuration that should be applied.
$newConfig['display']['default']['display_options']['pager']['options']['items_per_page'] = 24;
$successfulUpdate = TRUE;
foreach ([
'video_browser',
'image_browser',
] as $viewId) {
if (_thunder_media_update_config('views.view.' . $viewId, $newConfig, $expectedConfig)) {
$updateLogger
->info(t('Configuration is successfully changed for @view view.', [
'@view' => $viewId,
]));
}
else {
$successfulUpdate = FALSE;
$updateLogger
->warning(t('Unable to adjust entity browser view config'));
}
}
if (!$successfulUpdate) {
$updateLogger
->warning(t('We were unable to adjust entity browser view configs to display 24 instead of 20 items.'));
}
return $updateLogger
->output();
}
/**
* Enable empty fields module.
*/
function thunder_media_update_8105() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updater
->executeUpdate('thunder', 'v1_1__empty_fields');
return $updater
->logger()
->output();
}
/**
* Update url field labels in media entities.
*/
function thunder_media_update_8106() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updater
->executeUpdate('thunder', 'thunder_media_update_8106');
// Output logged messages to related channel of update execution.
return $updater
->logger()
->output();
}
/**
* Introduce enable_filefield_remove_button config item.
*/
function thunder_media_update_8107() {
$config = Drupal::configFactory()
->getEditable('thunder_media.settings');
if ($config
->get('enable_filefield_remove_button') === NULL) {
$config
->set('enable_filefield_remove_button', FALSE)
->save();
}
}
/**
* Use blazy for lazy loading.
*/
function thunder_media_update_8108() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updater
->executeUpdate('thunder', 'thunder_media_update_8108');
// Output logged messages to related channel of update execution.
return $updater
->logger()
->output();
}
/**
* Update twitter image style dimensions.
*/
function thunder_media_update_8109() {
/** @var \Drupal\update_helper\Updater $updater */
$updater = \Drupal::service('update_helper.updater');
$updater
->executeUpdate('thunder', 'thunder_media_update_8109');
// Output logged messages to related channel of update execution.
return $updater
->logger()
->output();
}
Functions
Name | Description |
---|---|
thunder_media_install | Install the thunder media integration. |
thunder_media_uninstall | Uninstall the thunder media integration. |
thunder_media_update_8001 | Rename config object. |
thunder_media_update_8002 | Change media_thumbnail image style. |
thunder_media_update_8003 | Add entity browser view sorting. |
thunder_media_update_8004 | Enable auto_open for gallery browser. |
thunder_media_update_8005 | Update dropzonejs widget file extension filtering for images. |
thunder_media_update_8006 | Enable auto_select on multiple_image_browser. |
thunder_media_update_8007 | Make instagrams responsive. |
thunder_media_update_8008 | New image style for entity browser. |
thunder_media_update_8009 | Set required fields for Image and Video bundles. |
thunder_media_update_8010 | Activate support for responsive images with Blazy. |
thunder_media_update_8011 | Remove "auto_select" from EB widget config, for those who don't support it. |
thunder_media_update_8012 | Change preview image style for image media bundle to "medium" image style. |
thunder_media_update_8013 | Import slick media display view configuration. |
thunder_media_update_8101 | Remove "Language" filter and add descriptions from media browsers. |
thunder_media_update_8102 | Introduce image and video paragraph. |
thunder_media_update_8103 | Adjust instagrams preview in backend. |
thunder_media_update_8104 | Increase number of items per page to 24 in entity browser. |
thunder_media_update_8105 | Enable empty fields module. |
thunder_media_update_8106 | Update url field labels in media entities. |
thunder_media_update_8107 | Introduce enable_filefield_remove_button config item. |
thunder_media_update_8108 | Use blazy for lazy loading. |
thunder_media_update_8109 | Update twitter image style dimensions. |
thunder_media_update_dependencies | Update hook dependencies. |
_thunder_media_update_config | Support for legacy configuration update behaviour. |
_thunder_media_update_entity_browser_config | Update entity browser configuration. |