You are here

function gridstack_update_8211 in GridStack 8.2

Simplified grid storage to just array values like seen at frontend.

File

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

Code

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

  // Simplify and remove keys:
  // Original: [{"x":1,"y":0,"width":2,"height":8}.
  // Now: [[1,0,2,8].
  $prefix = 'gridstack.optionset.';
  foreach ($config_factory
    ->listAll($prefix) as $name) {
    $id = str_replace($prefix, '', $name);
    if ($optionset = GridStack::load($id)) {
      $storage = $config_factory
        ->getEditable($name);
      $breakpoints = $storage
        ->get('options.breakpoints');
      foreach (array_keys(GridStackDefault::breakpoints()) as $breakpoint) {
        if (!isset($breakpoints[$breakpoint])) {
          continue;
        }
        $key = 'options.breakpoints.' . $breakpoint;
        if ($data = $storage
          ->get($key)) {
          if (isset($data['grids']) && ($grids = $data['grids'])) {
            $simplified = $optionset
              ->getJsonSummaryBreakpoints($breakpoint, $grids, FALSE);
            $storage
              ->set($key . '.grids', $simplified);

            // Removed image style for Responsive image at formatter level.
            if (isset($data['image_style'])) {
              $storage
                ->clear($key . '.image_style');
            }
            if (isset($data['nested']) && ($nested_grids = $data['nested'])) {
              $simplified = $optionset
                ->getJsonSummaryNestedBreakpoints($breakpoint, $nested_grids, $grids);
              $storage
                ->set($key . '.nested', $simplified);
            }
          }
        }
      }

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

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