diff --git a/core/includes/update.inc b/core/includes/update.inc index a5feb50..8fb6ca2 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -1597,3 +1597,93 @@ function update_add_cache_columns($table) { )); } } + +/** + * + * + * @param $block_name + * The full name of the block including block prefix (block.block). + * @param $module + * Block module name. + * @param $delta + * Block delta. + * @param $properties + * A key-value array of block entity properties. + */ +function update_block_to_config($block_name, $module, $delta, $properties) { + $config = config($block_name); + $node_types = _update_7000_node_get_types(); + + // Set default properties. + $defaults = array( + 'id' => '', + 'label' => '', + 'label_display' => 'visible', + 'uuid' => '', + 'region' => '', + 'weight' => 0, + 'module' => '', + 'status' => 0, + 'visibility' => array( + 'path' => array( + 'visibility' => 0, + 'pages' => '', + ), + 'role' => array( + 'roles' => array(), + ), + 'node_type' => array( + 'types' => ($node_types) ? array_reverse(array_keys($node_types)) : array(), + ), + 'visibility__active_tab' => 'edit-visibility-path', + ), + 'plugin' => '', + 'settings' => array( + 'cache' => -1, + ), + ); + + $properties += $defaults; + + // Get visible node types. + $types = db_select('block_node_type') + ->fields('block_node_type') + ->condition('module', $module) + ->condition('delta', $delta) + ->execute() + ->fetchAllKeyed(0, 0); + + if (!empty($types)) { + foreach ($types as $type_name) { + $properties['visibility']['node_type']['types'][$type_name] = $type_name; + } + } + + // Get visible roles. + $roles = db_select('block_role') + ->fields('block_role') + ->condition('module', $module) + ->condition('delta', $delta) + ->execute() + ->fetchAllKeyed(0, 0); + + if (!empty($roles)) { + foreach ($roles as $rid) { + $properties['visibility']['roles']['role'][] = $rid; + } + } + + // Config entity is new, need id. + if ($config->isNew()) { + $uuid = new UUID(); + $properties['uuid'] = $uuid->generate(); + } + + // Set entity properties. + $config->setData($properties); +// foreach ($properties as $key => $value) { +// $config->set($key, $value); +// } + + return $config->save(); +} diff --git a/core/modules/menu/menu.install b/core/modules/menu/menu.install index a76207b..67ba008 100644 --- a/core/modules/menu/menu.install +++ b/core/modules/menu/menu.install @@ -15,6 +15,15 @@ function menu_uninstall() { } /** + * Implements hook_update_dependencies(). + */ +function menu_update_dependencies() { + $dependencies['menu'][8005] = array( + 'block' => 8004, + ); +} + +/** * Moves menu settings from variables to config. * * @ingroup config_upgrade @@ -89,3 +98,35 @@ function menu_update_8004() { update_config_manifest_add('menu.menu', array($menu->menu_name)); } } + +/** + * Migrate menu blocks into configuration. + * + * @ingroup config_upgrade + */ +function menu_update_8005() { + $results = db_select('block')->condition('module', 'menu')->fields('block')->execute()->fetchAll(); + + foreach ($results as $block) { + $block_name = 'block.block.' . $block->theme . '.' . $block->delta; + $properties = array( + 'id' => $block->theme . '.' . $block->delta, + 'plugin' => 'menu_menu_block:' . $block->delta, + 'label' => $block->title, + 'weight' => $block->weight, + 'status' => $block->status, + 'region' => $block->region, + 'visibility' => array( + 'path' => array( + 'visibility' => $block->visibility, + 'pages' => $block->pages, + ), + ), + 'settings' => array( + 'cache' => $block->cache, + 'admin_label' => $block->title, + ), + ); + $ret = update_block_to_config($block_name, 'menu', $block->delta, $properties); + } +} diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 4f22958..d48e960 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -1057,5 +1057,35 @@ function user_update_8017() { } /** + * Migrate user blocks into configuration. + */ +function user_update_8018() { + $results = db_select('block')->condition('module', 'user')->fields('block')->execute()->fetchAll(); + + foreach ($results as $block) { + // Assemble properties to pass into block config update function. + $block_name = 'block.block.' . $block->theme . '.' . $block->delta; + $properties = array( + 'id' => $block->theme . '.' . $block->delta, + 'plugin' => 'user_' . $block->delta . '_block', + 'label' => $block->title, + 'weight' => $block->weight, + 'status' => $block->status, + 'region' => $block->region, + 'visibility' => array( + 'path' => array( + 'visibility' => $block->visibility, + 'pages' => $block->pages, + ), + ), + 'settings' => array( + 'cache' => $block->cache, + ), + ); + $ret = update_block_to_config($block_name, 'user', $block->delta, $properties); + } +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". */