commit c9b70c5bdf8ee545563dc4783bb2a5529b6d2088 Author: Matthew Radcliffe Date: Sat Jun 8 21:17:15 2013 -0400 Issue #1871700 by mradcliffe: Add aggregator block upgrade path. This slipped by me, but I'm confident that I have all blocks from Drupal 7 that are still in Drupal 8 (except views). diff --git a/core/modules/aggregator/aggregator.install b/core/modules/aggregator/aggregator.install index 7979eba..94135c9 100644 --- a/core/modules/aggregator/aggregator.install +++ b/core/modules/aggregator/aggregator.install @@ -331,3 +331,77 @@ function aggregator_update_8001() { 'initial' => Language::LANGCODE_DEFAULT, )); } + +/** + * Migrate aggregator blocks to configuration. + * + * @ingroup config_upgrade + */ +function aggregator_update_8002() { + // Provide a map with plugin name and query lookup routine for aggregator + // feeds and categories. + $map = array( + 'feed' => array( + 'plugin' => 'aggregator_feed_block', + 'query' => db_select('aggregator_feed')->fields('aggregator_feed', array('title')), + 'query field' => 'fid', + 'title translation' => '@title feed latest items', + ), + 'category' => array( + 'plugin' => 'aggregator_category_block', + 'query' => db_select('aggregator_category')->fields('aggregator_category', array('title')), + 'query field' => 'cid', + 'title translation' => '@title category latest items', + ), + ); + + $results = db_select('block')->condition('module', 'aggregator')->fields('block')->execute()->fetchAll(); + + foreach ($results as $block) { + // Assemble properties to pass into block config update function. + + // Get the block type and the derivative based on the delta. + list($type, $derivative) = explode('-', $block->delta); + + // Get the category or feed title from the respective table in the map. + $query = $map[$type]['query']; + $title = $query + ->condition($map[$type]['query field'], $derivative) + ->execute() + ->fetchField(); + + // Add the proper derivative title from translation in the map, and remove + // unnecessary characters. + $label = empty($block->title) ? t($map[$type]['title translation'], array('@title' => $title)) : $block->title; + $id = $block->theme . '.' . strtolower(preg_replace('/[^A-Za-z0-9\_]+/', '_', $label)); + $block_name = 'block.block.' . $id; + + $properties = array( + 'id' => $id, + 'plugin' => $map[$type]['plugin'] . ':' . $derivative, + 'weight' => $block->weight, + 'status' => $block->status, + 'region' => $block->region, + 'visibility' => array( + 'path' => array( + 'visibility' => $block->visibility, + 'pages' => $block->pages, + ), + 'role' => array( + 'roles' => array(), + ), + 'node_type' => array( + 'types' => array(), + ), + ), + 'settings' => array( + 'cache' => $block->cache, + 'label' => $label, + 'module' => 'aggregator', + 'block_count' => '10', + ), + ); + + update_block_to_config($block_name, 'aggregator', $block->delta, $properties); + } +}