You are here

function _markdown_update_config in Markdown 8.2

Updates all markdown config.

Parameters

bool $save: Flag indicating whether to save the config after its been updated.

array $defaultData: Optional. An array of default data to merge with any active config.

callable $normalizer: Optional. A specific normalizer callback that will be invoked on each config. If not specified, it will default to _markdown_normalize_config().

Return value

\Drupal\Core\Config\Config[] An array of config objects, keyed by config name.

1 call to _markdown_update_config()
markdown_post_update_8950 in ./markdown.post_update.php
Update configuration (run config export after).

File

./markdown.post_update.php, line 225
Markdown post updates.

Code

function _markdown_update_config($save = TRUE, array $defaultData = NULL, callable $normalizer = NULL) {
  if (!isset($normalizer)) {
    $normalizer = '_markdown_normalize_config';
  }
  if (!isset($defaultData)) {
    $defaultData = \Drupal::config('markdown.settings')
      ->get('parser') ?: [];
  }

  /** @var \Drupal\Core\Config\ConfigFactoryInterface $configFactory */
  $configFactory = \Drupal::service('config.factory');
  $configNames = [
    'markdown.settings',
  ];
  $parserManager = ParserManager::create();
  $available = $parserManager
    ->getDefinitions(FALSE);
  $installed = array_keys($parserManager
    ->installedDefinitions());
  foreach (array_keys($available) as $parserId) {
    if (in_array($parserId, $installed)) {
      $configNames[] = "markdown.parser.{$parserId}";
    }
    else {
      $configFactory
        ->getEditable("markdown.parser.{$parserId}")
        ->delete();
    }
  }

  /** @var \Drupal\filter\Entity\FilterFormat $format */
  foreach (FilterFormat::loadMultiple() as $format) {
    $configNames[] = $format
      ->getConfigDependencyName();
  }
  $configs = [];
  foreach ($configNames as $name) {
    $config = $configFactory
      ->getEditable($name);

    // Skip filters that don't already have markdown settings.
    if (strpos($name, 'filter.format.') === 0 && ($filters = $config
      ->get('filters') ?: []) && !isset($filters['markdown']['settings'])) {
      continue;
    }
    $normalizer($config, $defaultData, $save);
    $configs[$name] = $config;
  }
  return $configs;
}