You are here

function gridstack_update_8214 in GridStack 8.2

Removed jQueryUI-related settings for core Drupal and library deprecation.

File

./gridstack.install, line 293
Installation actions for GridStack.

Code

function gridstack_update_8214() {
  $config_factory = \Drupal::configFactory();
  $ui_settings = [
    'staticGrid',
    'draggable',
    'resizable',
    'disableDrag',
    'disableResize',
    'alwaysShowResizeHandle',
  ];

  // Revert old default optionsets.
  foreach ([
    'bootstrap',
    'default',
    'foundation',
    'frontend',
  ] as $key) {
    $config_path = drupal_get_path('module', 'gridstack') . '/config/install/gridstack.optionset.' . $key . '.yml';
    $data = Yaml::parseFile($config_path);
    $config_factory
      ->getEditable('gridstack.optionset.' . $key)
      ->setData($data)
      ->save(TRUE);
  }

  // Revert old sample optionsets.
  if (gridstack()
    ->getModuleHandler()
    ->moduleExists('gridstack_example')) {
    foreach ([
      'paz',
      'tagore',
    ] as $key) {
      $config_path = drupal_get_path('module', 'gridstack_example') . '/config/install/gridstack.optionset.' . $key . '.yml';
      $data = Yaml::parseFile($config_path);
      $config_factory
        ->getEditable('gridstack.optionset.' . $key)
        ->setData($data)
        ->save(TRUE);
    }
  }

  // Updates the rest.
  $prefix = 'gridstack.optionset.';
  foreach ($config_factory
    ->listAll($prefix) as $name) {
    $storage = $config_factory
      ->getEditable($name);
    $settings = $storage
      ->get('options.settings');

    // CSS Framework has no JS settings, of course, skip.
    if (empty($settings)) {
      continue;
    }

    // Removed jQuery UI related settings due to being deprecated.
    foreach ($ui_settings as $key) {
      if (isset($settings[$key])) {
        $storage
          ->clear('options.settings.' . $key);
      }
    }

    // Finally save it.
    $storage
      ->save(TRUE);

    // Also update front-end string storage.
    $settings = $storage
      ->get('options.settings');

    // Remove this, since we'll make this a dynamic multi-breakpoint column.
    unset($settings['column']);
    $storage
      ->set('json.settings', Json::encode($settings));

    // Finally save it.
    $storage
      ->save(TRUE);
  }

  // Clear the caches.
  \Drupal::entityTypeManager()
    ->clearCachedDefinitions();
}