You are here

cheeseburger_menu.install in Cheeseburger Menu 8.4

Same filename and directory in other branches
  1. 5.0.x cheeseburger_menu.install

File

cheeseburger_menu.install
View source
<?php

/**
 * Update config to match new schema.
 */
function cheeseburger_menu_update_8001(&$sandbox) {

  /** @var \Drupal\block\Entity\Block[] $blocks */
  $blocks = \Drupal::entityTypeManager()
    ->getStorage('block')
    ->loadByProperties([
    'plugin' => 'cheesebuger_menu_block',
  ]);
  foreach ($blocks as $block) {
    $settings = $block
      ->get('settings');
    foreach ($settings['menu'] as $id => &$data) {
      if ($data['title'] == 2) {
        $data['title'] = 'do_not_show';
      }
      elseif ($data['title'] == 1) {
        $data['title'] = 'use_default';
      }
      else {
        $data['title'] = 'manual';
      }
      if (!array_key_exists('collapsible_title', $data)) {
        $data['collapsible_title'] = FALSE;
      }
    }
    if (array_key_exists('vocabulary', $settings)) {
      $settings['taxonomy_vocabulary'] = $settings['vocabulary'];
      unset($settings['vocabulary']);
      foreach ($settings['taxonomy_vocabulary'] as $id => &$data) {
        if ($data['title'] == 2) {
          $data['title'] = 'do_not_show';
        }
        elseif ($data['title'] == 1) {
          $data['title'] = 'use_default';
        }
        else {
          $data['title'] = 'manual';
        }
        if (!array_key_exists('collapsible_title', $data)) {
          $data['collapsible_title'] = FALSE;
        }
      }
    }
    if (in_array('all', $settings['breakpoints'])) {
      $settings['breakpoints']['all'] = TRUE;
    }
    elseif (!array_key_exists('all', $settings['breakpoints'])) {
      $settings['breakpoints']['all'] = FALSE;
    }
    $block
      ->set('settings', $settings);
    $block
      ->save();
  }
}

Functions

Namesort descending Description
cheeseburger_menu_update_8001 Update config to match new schema.