filter.install 1.56 KB
Newer Older
1 2
<?php

3 4
/**
 * @file
5
 * Install, update, and uninstall functions for the Filter module.
6 7
 */

8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**
 * @addtogroup updates-7.x-to-8.x
 * @{
 */

/**
 * Moves filter_fallback settings from variable to config.
 *
 * @ingroup config_upgrade
 */
function filter_update_8000() {
  update_variables_to_config('filter.settings', array(
    'filter_fallback_format' => 'fallback_format',
  ));
22
}
23

24 25 26 27 28 29
/**
 * Migrate filter formats into configuration.
 *
 * @ingroup config_upgrade
 */
function filter_update_8001() {
30
  $uuid = \Drupal::service('uuid');
31 32 33 34 35 36 37 38 39 40 41
  $result = db_query('SELECT format, name, cache, status, weight FROM {filter_format}', array(), array('fetch' => PDO::FETCH_ASSOC));
  foreach ($result as $format) {
    $id = $format['format'];

    // Generate a UUID.
    $format['uuid'] = $uuid->generate();

    // Retrieve and prepare all filters.
    $filters = db_query('SELECT name, module, status, weight, settings FROM {filter} WHERE format = :format ORDER BY weight, module, name', array(
      ':format' => $id,
    ), array('fetch' => PDO::FETCH_ASSOC))->fetchAllAssoc('name');
42
    foreach ($filters as &$filter) {
43 44 45 46 47
      // The filter name is used as key only.
      unset($filter['name']);
      $filter['settings'] = unserialize($filter['settings']);
    }
    $format['filters'] = $filters;
48
    $format['status'] = (bool) $format['status'];
49 50

    // Save the config object.
51
    $config = \Drupal::config('filter.format.' . $id);
52 53 54 55 56
    $config->setData($format);
    $config->save();
  }
}

57 58 59 60
/**
 * @} End of "defgroup updates-7.x-to-8.x".
 * The next series of updates should start at 9000.
 */