You are here

function _thunder_media_update_config in Thunder 8.2

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.

Parameters

string $config_name: Configuration name that should be updated.

array $configuration: Configuration array to update.

array $expected_configuration: Only if current config is same like old config we are updating.

array $delete_keys: List of parent keys to remove. @see NestedArray::unsetValue()

Return value

bool Returns TRUE if update of configuration was successful.

See also

\Drupal\update_helper\Updater::updateConfig()

10 calls to _thunder_media_update_config()
thunder_media_update_8002 in modules/thunder_media/thunder_media.install
Change media_thumbnail image style.
thunder_media_update_8007 in modules/thunder_media/thunder_media.install
Make instagrams responsive.
thunder_media_update_8008 in modules/thunder_media/thunder_media.install
New image style for entity browser.
thunder_media_update_8009 in modules/thunder_media/thunder_media.install
Set required fields for Image and Video bundles.
thunder_media_update_8010 in modules/thunder_media/thunder_media.install
Activate support for responsive images with Blazy.

... See full list

File

modules/thunder_media/thunder_media.install, line 98
Contains.

Code

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;
}