You are here

function gridstack_update_8203 in GridStack 8.2

Updated optionsets to GridStack library v1.1+.

File

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

Code

function gridstack_update_8203() {
  $config_factory = \Drupal::configFactory();

  // Remove deprecated settings: customized.
  $config_factory
    ->getEditable('gridstack.settings')
    ->clear('customized')
    ->save();

  // Remove and update deprecated settings: width and height.
  foreach ($config_factory
    ->listAll('gridstack.optionset.') as $optionset_name) {
    $optionset = $config_factory
      ->getEditable($optionset_name);
    $options = $optionset
      ->get('options');

    // Settings are empty when using Bootstrap/ Foundation, skip.
    if (!empty($options['use_framework'])) {
      continue;
    }

    // Update with the new settings.
    $width = $optionset
      ->get('options.settings.width') ?: 0;
    if (!empty($width)) {
      $optionset
        ->set('options.settings.column', $width);
      $optionset
        ->set('options.settings.maxRow', $optionset
        ->get('options.settings.height'));

      // Remove deprecated settings: width, height.
      $optionset
        ->clear('options.settings.width');
      $optionset
        ->clear('options.settings.height');
      $settings = $optionset
        ->get('options.settings');

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

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

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