diff --cc core/includes/bootstrap.inc index 55a3875,dbe0555..0000000 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@@ -2456,6 -2437,64 +2456,67 @@@ function drupal_container(Container $ne if (isset($new_container)) { $container = $new_container; } ++<<<<<<< HEAD ++======= + if (!isset($container)) { + // This is only ever used by the installer and by run-tests.sh. + // @todo Remove this entire section once these have been converted to use a + // kernel. + $container = new ContainerBuilder(); + + // Register active configuration storage. + $container + ->register('config.cachedstorage.storage', 'Drupal\Core\Config\FileStorage') + ->addArgument(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY)); + // @todo Replace this with a cache.factory service plus 'config' argument. + $container + ->register('cache.config', 'Drupal\Core\Cache\CacheBackendInterface') + ->setFactoryClass('Drupal\Core\Cache\CacheFactory') + ->setFactoryMethod('get') + ->addArgument('config'); + + $container + ->register('config.storage', 'Drupal\Core\Config\CachedStorage') + ->addArgument(new Reference('config.cachedstorage.storage')) + ->addArgument(new Reference('cache.config')); + + // Register configuration object factory. + $container->register('config.subscriber.globalconf', 'Drupal\Core\EventSubscriber\ConfigGlobalOverrideSubscriber'); + $container->register('dispatcher', 'Symfony\Component\EventDispatcher\EventDispatcher') + ->addMethodCall('addSubscriber', array(new Reference('config.subscriber.globalconf'))); + $container->register('config.factory', 'Drupal\Core\Config\ConfigFactory') + ->addArgument(new Reference('config.storage')) + ->addArgument(new Reference('dispatcher')); + + // Register staging configuration storage. + $container + ->register('config.storage.staging', 'Drupal\Core\Config\FileStorage') + ->addArgument(config_get_config_directory(CONFIG_STAGING_DIRECTORY)); + + // Register the service for the default database connection. + $container->register('database', 'Drupal\Core\Database\Connection') + ->setFactoryClass('Drupal\Core\Database\Database') + ->setFactoryMethod('getConnection') + ->addArgument('default'); + // Register the KeyValueStore factory. + $container + ->register('keyvalue', 'Drupal\Core\KeyValueStore\KeyValueFactory') + ->addArgument(new Reference('service_container')); + $container + ->register('keyvalue.database', 'Drupal\Core\KeyValueStore\KeyValueDatabaseFactory') + ->addArgument(new Reference('database')); + + $container->register('path.alias_manager', 'Drupal\Core\Path\AliasManager') + ->addArgument(new Reference('database')) + ->addArgument(new Reference('keyvalue')); + + // Register the EntityManager. + $container->register('plugin.manager.entity', 'Drupal\Core\Entity\EntityManager'); + + // Register the Plugin UI. + $container->register('plugin.manager.system.plugin_ui', 'Drupal\system\Plugin\Type\PluginUIManager'); + } ++>>>>>>> Issue #1535868 by Jody Lynn, EclipseGc, tim.plunkett, naxoc, sdboyer, tizzo, sun, effulgentsia: Convert all blocks into plugins. return $container; } diff --cc core/modules/block/block.admin.inc index ffa0b0b,581866f..0000000 --- a/core/modules/block/block.admin.inc +++ b/core/modules/block/block.admin.inc @@@ -184,30 -179,14 +179,14 @@@ function block_admin_display_form($form * @see block_admin_display_form() */ function block_admin_display_form_submit($form, &$form_state) { - $transaction = db_transaction(); - try { - foreach ($form_state['values']['blocks'] as $block) { - $block['status'] = (int) ($block['region'] != BLOCK_REGION_NONE); - $block['region'] = $block['status'] ? $block['region'] : ''; - db_update('block') - ->fields(array( - 'status' => $block['status'], - 'weight' => $block['weight'], - 'region' => $block['region'], - )) - ->condition('module', $block['module']) - ->condition('delta', $block['delta']) - ->condition('theme', $block['theme']) - ->execute(); - } - } - catch (Exception $e) { - $transaction->rollback(); - watchdog_exception('block', $e); - throw $e; + foreach ($form_state['values']['blocks'] as $block) { + $config = config($block['config_id']); + $config->set('weight', $block['weight']); + $config->set('region', $block['region']); + $config->save(); } drupal_set_message(t('The block settings have been updated.')); - cache_invalidate(array('content' => TRUE)); + cache_invalidate_tags(array('content' => TRUE)); } /** @@@ -537,186 -285,16 +285,199 @@@ function block_admin_configure_validate * @see block_admin_configure_validate() */ function block_admin_configure_submit($form, &$form_state) { ++<<<<<<< HEAD + if (!form_get_errors()) { + $transaction = db_transaction(); + try { + db_update('block') + ->fields(array( + 'visibility' => (int) $form_state['values']['visibility'], + 'pages' => trim($form_state['values']['pages']), + 'custom' => (int) $form_state['values']['custom'], + 'title' => $form_state['values']['title'], + )) + ->condition('module', $form_state['values']['module']) + ->condition('delta', $form_state['values']['delta']) + ->execute(); + + db_delete('block_role') + ->condition('module', $form_state['values']['module']) + ->condition('delta', $form_state['values']['delta']) + ->execute(); + $query = db_insert('block_role')->fields(array('rid', 'module', 'delta')); + foreach (array_filter($form_state['values']['roles']) as $rid) { + $query->values(array( + 'rid' => $rid, + 'module' => $form_state['values']['module'], + 'delta' => $form_state['values']['delta'], + )); + } + $query->execute(); + + // Store regions per theme for this block. + foreach ($form_state['values']['regions'] as $theme => $region) { + db_merge('block') + ->key(array('theme' => $theme, 'delta' => $form_state['values']['delta'], 'module' => $form_state['values']['module'])) + ->fields(array( + 'region' => ($region == BLOCK_REGION_NONE ? '' : $region), + 'pages' => trim($form_state['values']['pages']), + 'status' => (int) ($region != BLOCK_REGION_NONE), + )) + ->execute(); + } + + // Update the block visibility settings if we have settings to store + // for the existing languages. + if (module_exists('language') && isset($form_state['values']['langcodes'])) { + db_delete('block_language') + ->condition('module', $form_state['values']['module']) + ->condition('delta', $form_state['values']['delta']) + ->execute(); + $query = db_insert('block_language')->fields(array( + 'type', 'langcode', 'module', 'delta' + )); + foreach (array_filter($form_state['values']['langcodes']) as $langcode) { + $query->values(array( + 'type' => $form_state['values']['language_type'], + 'langcode' => $langcode, + 'module' => $form_state['values']['module'], + 'delta' => $form_state['values']['delta'], + )); + } + $query->execute(); + } + + module_invoke($form_state['values']['module'], 'block_save', $form_state['values']['delta'], $form_state['values']); + } + catch (Exception $e) { + $transaction->rollback(); + watchdog_exception('block', $e); + throw $e; + } + drupal_set_message(t('The block configuration has been saved.')); + cache_invalidate_tags(array('content' => TRUE)); + $form_state['redirect'] = 'admin/structure/block'; + } +} + +/** + * Form constructor for the add block form. + * + * @see block_menu() + * @see block_add_block_form_validate() + * @see block_add_block_form_submit() + * @ingroup forms + */ +function block_add_block_form($form, &$form_state) { + return block_admin_configure($form, $form_state, 'block', NULL); +} + +/** + * Form validation handler for block_add_block_form(). + * + * @see block_add_block_form() + * @see block_add_block_form_submit() + */ +function block_add_block_form_validate($form, &$form_state) { + $custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE info = :info', 0, 1, array(':info' => $form_state['values']['info']))->fetchField(); + + if (empty($form_state['values']['info']) || $custom_block_exists) { + form_set_error('info', t('Ensure that each block description is unique.')); + } +} + +/** + * Form submission handler for block_add_block_form(). + * + * Saves the new custom block. + * + * @see block_add_block_form() + * @see block_add_block_form_validate() + */ +function block_add_block_form_submit($form, &$form_state) { + $delta = db_insert('block_custom') + ->fields(array( + 'body' => $form_state['values']['body']['value'], + 'info' => $form_state['values']['info'], + 'format' => $form_state['values']['body']['format'], + )) + ->execute(); + // Store block delta to allow other modules to work with new block. + $form_state['values']['delta'] = $delta; + + $query = db_insert('block')->fields(array('visibility', 'pages', 'custom', 'title', 'module', 'theme', 'status', 'weight', 'delta', 'cache')); + foreach (list_themes() as $key => $theme) { + if ($theme->status) { + $query->values(array( + 'visibility' => (int) $form_state['values']['visibility'], + 'pages' => trim($form_state['values']['pages']), + 'custom' => (int) $form_state['values']['custom'], + 'title' => $form_state['values']['title'], + 'module' => $form_state['values']['module'], + 'theme' => $theme->name, + 'status' => 0, + 'weight' => 0, + 'delta' => $delta, + 'cache' => DRUPAL_NO_CACHE, + )); + } + } + $query->execute(); + + $query = db_insert('block_role')->fields(array('rid', 'module', 'delta')); + foreach (array_filter($form_state['values']['roles']) as $rid) { + $query->values(array( + 'rid' => $rid, + 'module' => $form_state['values']['module'], + 'delta' => $delta, + )); + } + $query->execute(); + + // Store regions per theme for this block. + foreach ($form_state['values']['regions'] as $theme => $region) { + db_merge('block') + ->key(array('theme' => $theme, 'delta' => $delta, 'module' => $form_state['values']['module'])) + ->fields(array( + 'region' => ($region == BLOCK_REGION_NONE ? '' : $region), + 'pages' => trim($form_state['values']['pages']), + 'status' => (int) ($region != BLOCK_REGION_NONE), + )) + ->execute(); + } + + // Update the block visibility settings if we have settings to store + // for the existing languages. + if (module_exists('language') && isset($form_state['values']['langcodes'])) { + $query = db_insert('block_language')->fields(array( + 'type', 'langcode', 'module', 'delta' + )); + foreach (array_filter($form_state['values']['langcodes']) as $langcode) { + $query->values(array( + 'type' => $form_state['values']['language_type'], + 'langcode' => $langcode, + 'module' => $form_state['values']['module'], + 'delta' => $form_state['values']['delta'], + )); + } + $query->execute(); + } + + drupal_set_message(t('The block has been created.')); + cache_invalidate_tags(array('content' => TRUE)); + $form_state['redirect'] = 'admin/structure/block'; ++======= + $form['#instance']->configureSubmitWrapper($form, $form_state); + $config_values = $form['#instance']->getConfig(); + $machine_name = 'plugin.core.block.' . $form_state['values']['theme'] . '.' . $form_state['values']['machine_name']; + $config = config($machine_name); + $config->set('id', $form['#instance']->getPluginId()); + foreach ($config_values as $key => $value) { + $config->set($key, $value); + } + $config->save(); + $form_state['redirect'] = 'admin/structure/block/list/block_plugin_ui:' . $form_state['values']['theme']; ++>>>>>>> Issue #1535868 by Jody Lynn, EclipseGc, tim.plunkett, naxoc, sdboyer, tizzo, sun, effulgentsia: Convert all blocks into plugins. } /** @@@ -741,31 -322,15 +505,39 @@@ function block_admin_block_delete($form } /** - * Form submission handler for block_custom_block_delete(). + * Form submission handler for block_admin_block_delete(). * - * @see block_custom_block_delete() + * @see block_admin_block_delete() */ ++<<<<<<< HEAD +function block_custom_block_delete_submit($form, &$form_state) { + db_delete('block_custom') + ->condition('bid', $form_state['values']['bid']) + ->execute(); + db_delete('block') + ->condition('module', 'block') + ->condition('delta', $form_state['values']['bid']) + ->execute(); + db_delete('block_role') + ->condition('module', 'block') + ->condition('delta', $form_state['values']['bid']) + ->execute(); + db_delete('block_language') + ->condition('module', 'block') + ->condition('delta', $form_state['values']['bid']) + ->execute(); + + drupal_set_message(t('The block %name has been removed.', array('%name' => $form_state['values']['info']))); + cache_invalidate_tags(array('content' => TRUE)); + $form_state['redirect'] = 'admin/structure/block'; + return; ++======= + function block_admin_block_delete_submit($form, &$form_state) { + $config = config($form_state['values']['id']); + $config->delete(); + drupal_set_message(t('The block %name has been removed.', array('%name' => $form_state['values']['subject']))); + $form_state['redirect'] = 'admin/structure/block/list/' . $form_state['values']['theme']; ++>>>>>>> Issue #1535868 by Jody Lynn, EclipseGc, tim.plunkett, naxoc, sdboyer, tizzo, sun, effulgentsia: Convert all blocks into plugins. } /** diff --cc core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php index 411beb1,91cc7c1..0000000 --- a/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php @@@ -33,16 -35,19 +35,23 @@@ class BlockHtmlIdTest extends WebTestBa parent::setUp(); // Create an admin user, log in and enable test blocks. - $this->admin_user = $this->drupalCreateUser(array('administer blocks', 'access administration pages')); - $this->drupalLogin($this->admin_user); - - // Enable our test block. - $edit['blocks[block_test_test_html_id][region]'] = 'sidebar_first'; - $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); + $this->adminUser = $this->drupalCreateUser(array('administer blocks', 'access administration pages')); + $this->drupalLogin($this->adminUser); - // Make sure the block has some content so it will appear + // Make sure the block has some content so it will appear. $current_content = $this->randomName(); ++<<<<<<< HEAD + state()->set('block_test.content', $current_content); ++======= + variable_set('block_test_content', $current_content); + + // Enable our test block. + $default_theme = variable_get('theme_default', 'stark'); + $block = array(); + $block['machine_name'] = 'test_id_block'; + $block['region'] = 'sidebar_first'; + $this->drupalPost('admin/structure/block/manage/test_html_id' . '/' . $default_theme, array('machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block')); ++>>>>>>> Issue #1535868 by Jody Lynn, EclipseGc, tim.plunkett, naxoc, sdboyer, tizzo, sun, effulgentsia: Convert all blocks into plugins. } /** diff --cc core/modules/block/lib/Drupal/block/Tests/BlockTest.php index 7446052,1dec612..0000000 --- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php @@@ -406,19 -257,31 +257,35 @@@ class CustomBlockTest extends WebTestBa module_enable(array('block_test')); $this->assertTrue(module_exists('block_test'), 'Test block module enabled.'); - // Our new block should be inserted in the database when we visit the - // block management page. - $this->drupalGet('admin/structure/block'); + // Add a test block. + $plugin = block_manager()->getDefinition('test_cache'); + + $block = array(); + $block['id'] = 'test_cache'; + $block['machine_name'] = $this->randomName(8); + $block['theme'] = variable_get('theme_default', 'stark'); + $block['region'] = 'header'; + $this->drupalPost('admin/structure/block/manage/' . $block['id'] . '/' . $block['theme'], array('machine_name' => $block['machine_name'], 'region' => $block['region']), t('Save block')); + // Our test block's caching should default to DRUPAL_CACHE_PER_ROLE. - $current_caching = db_query("SELECT cache FROM {block} WHERE module = 'block_test' AND delta = 'test_cache'")->fetchField(); - $this->assertEqual($current_caching, DRUPAL_CACHE_PER_ROLE, 'Test block cache mode defaults to DRUPAL_CACHE_PER_ROLE.'); + $block['config_id'] = 'plugin.core.block.' . $block['theme'] . '.' . $block['machine_name']; + $instance = block_load($block['config_id']); + $config = $instance->getConfig(); + $this->assertEqual($config['cache'], DRUPAL_CACHE_PER_ROLE, t('Test block cache mode defaults to DRUPAL_CACHE_PER_ROLE.')); // Disable caching for this block. ++<<<<<<< HEAD + state()->set('block_test.caching', DRUPAL_NO_CACHE); ++======= + $block_config = config($block['config_id']); + $block_config->set('cache', DRUPAL_NO_CACHE); + $block_config->save(); ++>>>>>>> Issue #1535868 by Jody Lynn, EclipseGc, tim.plunkett, naxoc, sdboyer, tizzo, sun, effulgentsia: Convert all blocks into plugins. // Flushing all caches should call _block_rehash(). $this->resetAll(); - // Verify that the database is updated with the new caching mode. - $current_caching = db_query("SELECT cache FROM {block} WHERE module = 'block_test' AND delta = 'test_cache'")->fetchField(); - $this->assertEqual($current_caching, DRUPAL_NO_CACHE, "Test block's database entry updated to DRUPAL_NO_CACHE."); + // Verify that block is updated with the new caching mode. + $instance = block_load($block['config_id']); + $config = $instance->getConfig(); + $this->assertEqual($config['cache'], DRUPAL_NO_CACHE, t("Test block's database entry updated to DRUPAL_NO_CACHE.")); } } diff --cc core/modules/block/tests/block_test.module index 4105294,03f94b0..0000000 --- a/core/modules/block/tests/block_test.module +++ b/core/modules/block/tests/block_test.module @@@ -12,25 -12,3 +12,28 @@@ function block_test_system_theme_info( $themes['block_test_theme'] = drupal_get_path('module', 'block_test') . '/themes/block_test_theme/block_test_theme.info'; return $themes; } ++<<<<<<< HEAD + +/** + * Implements hook_block_info(). + */ +function block_test_block_info() { + $blocks['test_cache'] = array( + 'info' => t('Test block caching'), + 'cache' => state()->get('block_test.caching') ?: DRUPAL_CACHE_PER_ROLE, + ); + + $blocks['test_html_id'] = array( + 'info' => t('Test block html id'), + ); + return $blocks; +} + +/** + * Implements hook_block_view(). + */ +function block_test_block_view($delta = 0) { + return array('content' => state()->get('block_test.content')); +} ++======= ++>>>>>>> Issue #1535868 by Jody Lynn, EclipseGc, tim.plunkett, naxoc, sdboyer, tizzo, sun, effulgentsia: Convert all blocks into plugins.