diff --git a/core/includes/update.inc b/core/includes/update.inc index a5feb50..ae22191 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -1597,3 +1597,93 @@ function update_add_cache_columns($table) { )); } } + +/** + * Create block config entity from properties passed in by module. + * + * @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' => '', + 'uuid' => '', + 'region' => '', + 'weight' => 0, + '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( + 'label' => '', + 'label_display' => 'visible', + 'module' => '', + '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/book/book.install b/core/modules/book/book.install index 7d70a02..7121a96 100644 --- a/core/modules/book/book.install +++ b/core/modules/book/book.install @@ -109,3 +109,35 @@ function book_update_8000() { } } + +/** + * Migrate book navigation block to config including book navigation + * configuration. + */ +function book_update_8001() { + $results = db_select('block')->condition('module', 'book')->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' => 'block_' . $block->delta, + 'weight' => $block->weight, + 'status' => $block->status, + 'region' => $block->region, + 'visibility' => array( + 'path' => array( + 'visibility' => $block->visibility, + 'pages' => $block->pages, + ), + ), + 'settings' => array( + 'cache' => $block->cache, + 'label' => $block->title, + 'block_mode' => config('book.settings')->get('block.navigation.mode', 'all pages'), + ), + ); + $ret = update_block_to_config($block_name, 'book', $block->delta, $properties); + } +} diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index b022efb..5270384 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -394,6 +394,47 @@ function comment_update_8004() { } /** + * Migrate comment block to config. + */ +function comment_update_8005() { + // Did comment_block_count get updated? + update_variables_to_config('comment.settings', array( + 'comment_block_count' => 'block.recent_comments.limit', + )); + + $results = db_select('block') + ->condition('module', 'comment') + ->condition('delta', 'recent') + ->fields('block') + ->execute() + ->fetchAll(); + + foreach ($results as $block) { + // Assemble properties to pass into block config update function. + $block_name = 'block.block.' . $block->theme . '.recent_comments'; + $properties = array( + 'id' => $block->theme . '.recent_comments', + 'plugin' => 'recent_comments', + 'weight' => $block->weight, + 'status' => $block->status, + 'region' => $block->region, + 'visibility' => array( + 'path' => array( + 'visibility' => $block->visibility, + 'pages' => $block->pages, + ), + ), + 'settings' => array( + 'cache' => $block->cache, + 'label' => $block->title, + 'block_count' => config('comment.settings')->get('block.recent_comments.limit', 10), + ), + ); + $ret = update_block_to_config($block_name, 'comment', $block->delta, $properties); + } +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/comment/config/comment.settings.yml b/core/modules/comment/config/comment.settings.yml new file mode 100644 index 0000000..039f966 --- /dev/null +++ b/core/modules/comment/config/comment.settings.yml @@ -0,0 +1,3 @@ +block: + recent: + limit: '10' diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index a6641a2..2f870ce 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -273,3 +273,43 @@ function forum_update_8000() { 'forum_block_num_new' => 'block.new.limit', )); } + +/** + * Migrate forum new and active blocks to configuration. + */ +function forum_update_8001() { + // Block name map from Drupal 7 delta to Drupal 8. + $map = array( + 'new' => 'new_forum_topics', + 'active' => 'active_forum_topics', + ); + + $results = db_select('block')->condition('module', 'forum')->fields('block')->execute()->fetchAll(); + + foreach ($results as $block) { + // Assemble properties to pass into block config update function. + $block_name = 'block.block.' . $block->theme . '.' . $map[$block->delta]; + $properties = array( + 'id' => $block->theme . '.' . $block->delta, + 'plugin' => 'forum_' . $block->delta . '_block', + 'weight' => $block->weight, + 'status' => $block->status, + 'region' => $block->region, + 'visibility' => array( + 'path' => array( + 'visibility' => $block->visibility, + 'pages' => $block->pages, + ), + ), + 'settings' => array( + 'cache' => $block->cache, + 'label' => $block->title, + 'properties' => array( + 'administrative' => TRUE, + ), + 'block_count' => config('book.settings')->get('block.' . $block->delta . '.limit', 5), + ), + ); + $ret = update_block_to_config($block_name, 'forum', $block->delta, $properties); + } +} diff --git a/core/modules/menu/menu.install b/core/modules/menu/menu.install index a76207b..cf18bb9 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,34 @@ 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, + 'weight' => $block->weight, + 'status' => $block->status, + 'region' => $block->region, + 'visibility' => array( + 'path' => array( + 'visibility' => $block->visibility, + 'pages' => $block->pages, + ), + ), + 'settings' => array( + 'cache' => $block->cache, + 'label' => $block->title, + ), + ); + $ret = update_block_to_config($block_name, 'menu', $block->delta, $properties); + } +} diff --git a/core/modules/node/config/node.settings.yml b/core/modules/node/config/node.settings.yml index 9562864..b4b03af 100644 --- a/core/modules/node/config/node.settings.yml +++ b/core/modules/node/config/node.settings.yml @@ -1 +1,4 @@ items_per_page: '10' +block: + recent_content: + limit: '10' diff --git a/core/modules/node/node.install b/core/modules/node/node.install index b0735d3..74f087c 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -666,12 +666,15 @@ function node_update_8008() { } /** - * Coverts default_nodes_main variable to config. + * Coverts default_nodes_main and node_recent_block_count variables to config. * * @ingroup config_upgrade */ function node_update_8009() { - update_variables_to_config('node.settings', array('default_nodes_main' => 'items_per_page')); + update_variables_to_config('node.settings', array( + 'default_nodes_main' => 'items_per_page', + 'node_recent_block_count' => 'block.recent_content.limit', + )); } /** @@ -752,6 +755,52 @@ function node_update_8015() { } /** + * Migrate recent content and syndicate blocks to config. + */ +function node_update_8016() { + // Block name and id mapping. + $map = array( + 'recent' => 'recent_content', + 'syndicate' => 'syndicate', + ); + + $results = db_select('block') + ->condition('module', 'node') + ->condition('delta', array('recent', 'syndicate'), 'IN') + ->fields('block') + ->execute() + ->fetchAll(); + + foreach ($results as $block) { + // Assemble properties to pass into block config update function. + $block_name = 'block.block.' . $block->theme . '.' . $map[$block->delta]; + $properties = array( + 'id' => $block->theme . '.' . $map[$block->delta], + 'plugin' => 'node.' . $block->delta . '.block', + 'weight' => $block->weight, + 'status' => $block->status, + 'region' => $block->region, + 'visibility' => array( + 'path' => array( + 'visibility' => $block->visibility, + 'pages' => $block->pages, + ), + ), + 'settings' => array( + 'cache' => $block->cache, + 'label' => $block->title, + ), + ); + + if ($block->delta == 'recent') { + $properties['block_count'] = config('node.settings')->get('block.recent_content.limit', 10); + } + + $ret = update_block_to_config($block_name, 'node', $block->delta, $properties); + } +} + +/** * @} End of "addtogroup updates-7.x-to-8.x" * The next series of updates should start at 9000. */ diff --git a/core/modules/search/search.install b/core/modules/search/search.install index 40a569c..975bf58 100644 --- a/core/modules/search/search.install +++ b/core/modules/search/search.install @@ -214,3 +214,38 @@ function search_update_8001() { )); db_add_primary_key('search_index', array('word', 'sid', 'langcode', 'type')); } + +/** + * Migrate search block to config. + */ +function search_update_8002() { + $results = db_select('block') + ->condition('module', 'search') + ->condition('delta', 'form') + ->fields('block') + ->execute() + ->fetchAll(); + + foreach ($results as $block) { + // Assemble properties to pass into block config update function. + $block_name = 'block.block.' . $block->theme . '.search_form'; + $properties = array( + 'id' => $block->theme . '.search_form', + 'plugin' => 'search_block_form', + 'weight' => $block->weight, + 'status' => $block->status, + 'region' => $block->region, + 'visibility' => array( + 'path' => array( + 'visibility' => $block->visibility, + 'pages' => $block->pages, + ), + ), + 'settings' => array( + 'cache' => $block->cache, + 'label' => $block->title, + ), + ); + $ret = update_block_to_config($block_name, 'search', $block->delta, $properties); + } +} diff --git a/core/modules/shortcut/shortcut.install b/core/modules/shortcut/shortcut.install index 4a84150..7547ef7 100644 --- a/core/modules/shortcut/shortcut.install +++ b/core/modules/shortcut/shortcut.install @@ -102,6 +102,41 @@ function shortcut_update_8001() { } /** + * Migrate shortcuts block to config. + */ +function shortcut_update_8002() { + $results = db_select('block') + ->condition('module', 'shortcut') + ->condition('delta', 'shortcuts') + ->fields('block') + ->execute() + ->fetchAll(); + + foreach ($results as $block) { + // Assemble properties to pass into block config update function. + $block_name = 'block.block.' . $block->theme . '.shortcuts'; + $properties = array( + 'id' => $block->theme . '.shortcuts', + 'plugin' => 'shortcuts', + 'weight' => $block->weight, + 'status' => $block->status, + 'region' => $block->region, + 'visibility' => array( + 'path' => array( + 'visibility' => $block->visibility, + 'pages' => $block->pages, + ), + ), + 'settings' => array( + 'cache' => $block->cache, + 'label' => $block->title, + ), + ); + $ret = update_block_to_config($block_name, 'shortcut', $block->delta, $properties); + } +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BlockUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BlockUpgradePathTest.php index 45f2efb..48283d7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/BlockUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/BlockUpgradePathTest.php @@ -24,7 +24,7 @@ public static function getInfo() { public function setUp() { $this->databaseDumpFiles = array( - drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.minimal.database.php.gz', + drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz', ); parent::setUp(); } @@ -60,6 +60,16 @@ public function testBlockUpgradeTitleLength() { // Confirm that the custom block cannot be created with title longer than // the maximum number of characters. $this->assertText('Title cannot be longer than 255 characters'); + + // Change an upgraded block. + $edit = array( + 'settings[label]' => $this->randomName(50), + ); + $this->drupalPost('admin/structure/block/manage/bartik.login/configure', $edit, t('Save block')); + $this->drupalLogout(); + $this->drupalGet(''); + $this->assertText($edit['settings[label]'], 'Bartik user login block title successfully changed.'); + } } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index b7b4209..42ad553 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -2193,6 +2193,68 @@ function system_update_8056() { } /** + * Migrate system blocks to config. + */ +function system_update_8057() { + $results = db_select('block')->condition('module', 'system')->fields('block')->execute()->fetchAll(); + + // There are a variety of block names and plugins that are not consistent. + $plugin_map = array( + 'main' => array( + 'plugin' => 'system_main_block', + 'name' => 'content', + ), + 'help' => array( + 'plugin' => 'system_help_block', + 'name' => 'help', + ), + 'powered-by' => array( + 'plugin' => 'system_powered_by_block', + 'name' => 'powered', + ), + 'tools' => array( + 'plugin' => 'system_menu_block:menu-tools', + 'name' => 'tools', + ), + 'admin' => array( + 'plugin' => 'system_menu_block:menu-admin', + 'name' => 'administration', + ), + 'account' => array( + 'plugin' => 'system_menu_block:menu-account', + 'name' => 'user_account_menu', + ), + 'main' => array( + 'plugin' => 'system_menu_block:menu-main', + 'name' => 'main_navigation', + ), + ); + + foreach ($results as $block) { + // Assemble properties to pass into block config update function. + $block_name = 'block.block.' . $block->theme . '.' . $plugin_map[$block->delta]['name']; + $properties = array( + 'id' => $block->theme . '.' . $plugin_map[$block->delta]['name'], + 'plugin' => $plugin_map[$block->delta]['plugin'], + 'weight' => $block->weight, + 'status' => $block->status, + 'region' => $block->region, + 'visibility' => array( + 'path' => array( + 'visibility' => $block->visibility, + 'pages' => $block->pages, + ), + ), + 'settings' => array( + 'cache' => $block->cache, + 'label' => $block->title, + ), + ); + $ret = update_block_to_config($block_name, 'system', $block->delta, $properties); + } +} + +/** * @} End of "defgroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 4f22958..671fbea 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', + 'weight' => $block->weight, + 'status' => $block->status, + 'region' => $block->region, + 'visibility' => array( + 'path' => array( + 'visibility' => $block->visibility, + 'pages' => $block->pages, + ), + ), + 'settings' => array( + 'cache' => $block->cache, + 'label' => $block->title, + ), + ); + $ret = update_block_to_config($block_name, 'user', $block->delta, $properties); + } +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". */