TRUE
(experts only)'));
- $title = t('Pages or PHP code');
- $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => ''));
- }
- else {
- $title = t('Pages');
- }
- $form['visibility']['path']['visibility'] = array(
- '#type' => 'radios',
- '#title' => t('Show block on specific pages'),
- '#options' => $options,
- '#default_value' => isset($block->visibility) ? $block->visibility : BLOCK_VISIBILITY_NOTLISTED,
- );
- $form['visibility']['path']['pages'] = array(
- '#type' => 'textarea',
- '#title' => '' . $title . '',
- '#default_value' => isset($block->pages) ? $block->pages : '',
- '#description' => $description,
- );
- }
-
- // Configure the block visibility per language.
- if (module_exists('language') && language_multilingual()) {
- $configurable_language_types = language_types_get_configurable();
- $existing_language_settings = db_query("SELECT type, langcode FROM {block_language} WHERE module = :module AND delta = :delta", array(
- ':module' => $form['module']['#value'],
- ':delta' => $form['delta']['#value'],
- ))->fetchAll();
- $default_langcode_options = array();
- $default_language_type = $configurable_language_types[0];
- foreach ($existing_language_settings as $setting) {
- $default_langcode_options[] = $setting->langcode;
- // Overwrite default language type if we have it set. Although this
- // theoretically would allow per language type association, our UI
- // only allows language type association overall for a block, so we
- // only need a single value.
- $default_language_type = $setting->type;
- }
-
- // Fetch languages.
- $languages = language_list(LANGUAGE_ALL);
- foreach ($languages as $language) {
- // @TODO $language->name is not wrapped with t(), it should be replaced
- // by CMI translation implementation.
- $langcodes_options[$language->langcode] = $language->name;
- }
- $form['visibility']['language'] = array(
- '#type' => 'details',
- '#title' => t('Languages'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#group' => 'visibility',
- '#weight' => 5,
- );
- // If there are multiple configurable language types, let the user pick
- // which one should be applied to this visibility setting. This way users
- // can limit blocks by interface language or content language for exmaple.
- $language_types = language_types_info();
- $language_type_options = array();
- foreach ($configurable_language_types as $type_key) {
- $language_type_options[$type_key] = $language_types[$type_key]['name'];
- }
- $form['visibility']['language']['language_type'] = array(
- '#type' => 'radios',
- '#title' => t('Language type'),
- '#options' => $language_type_options,
- '#default_value' => $default_language_type,
- '#access' => count($language_type_options) > 1,
- );
- $form['visibility']['language']['langcodes'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Show this block only for specific languages'),
- '#default_value' => $default_langcode_options,
- '#options' => $langcodes_options,
- '#description' => t('Show this block only for the selected language(s). If you select no languages, the block will be visibile in all languages.'),
- );
+ elseif (!$theme && isset($config['config_id'])) {
+ list(, , , $theme) = explode('.', $config['config_id']);
}
-
- // Per-role visibility.
- $default_role_options = db_query("SELECT rid FROM {block_role} WHERE module = :module AND delta = :delta", array(
- ':module' => $block->module,
- ':delta' => $block->delta,
- ))->fetchCol();
- $role_options = array_map('check_plain', user_roles());
- $form['visibility']['role'] = array(
- '#type' => 'details',
- '#title' => t('Roles'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#group' => 'visibility',
- '#weight' => 10,
- );
- $form['visibility']['role']['roles'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Show block for specific roles'),
- '#default_value' => $default_role_options,
- '#options' => $role_options,
- '#description' => t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
- );
-
- // Per-user visibility.
- $form['visibility']['user'] = array(
- '#type' => 'details',
- '#title' => t('Users'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#group' => 'visibility',
- '#weight' => 20,
- );
- $form['visibility']['user']['custom'] = array(
- '#type' => 'radios',
- '#title' => t('Customizable per user'),
- '#options' => array(
- BLOCK_CUSTOM_FIXED => t('Not customizable'),
- BLOCK_CUSTOM_ENABLED => t('Customizable, visible by default'),
- BLOCK_CUSTOM_DISABLED => t('Customizable, hidden by default'),
- ),
- '#description' => t('Allow individual users to customize the visibility of this block in their account settings.'),
- '#default_value' => isset($block->custom) ? $block->custom : BLOCK_CUSTOM_FIXED,
- );
-
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save block'),
+ $form['theme'] = array(
+ '#type' => 'value',
+ '#value' => $theme,
);
-
+ $form += $instance->configureWrapper($form, $form_state);
return $form;
}
@@ -519,15 +275,7 @@ function block_admin_configure($form, &$form_state, $module, $delta) {
* @see block_admin_configure_submit()
*/
function block_admin_configure_validate($form, &$form_state) {
- if ($form_state['values']['module'] == 'block') {
- $custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE bid <> :bid AND info = :info', 0, 1, array(
- ':bid' => $form_state['values']['delta'],
- ':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['#instance']->configureValidateWrapper($form, $form_state);
}
/**
@@ -537,186 +285,16 @@ function block_admin_configure_validate($form, &$form_state) {
* @see block_admin_configure_validate()
*/
function block_admin_configure_submit($form, &$form_state) {
- 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(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);
}
-}
-
-/**
- * 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(array('content' => TRUE));
- $form_state['redirect'] = 'admin/structure/block';
+ $config->save();
+ $form_state['redirect'] = 'admin/structure/block/list/block_plugin_ui:' . $form_state['values']['theme'];
}
/**
@@ -729,43 +307,30 @@ function block_add_block_form_submit($form, &$form_state) {
* The unique ID of the block within the context of $module.
*
* @see block_menu()
- * @see block_custom_block_delete_submit()
+ * @see block_admin_block_delete_submit()
*/
-function block_custom_block_delete($form, &$form_state, $module, $delta) {
- $block = block_load($module, $delta);
- $custom_block = block_custom_block_get($block->delta);
- $form['info'] = array('#type' => 'hidden', '#value' => $custom_block['info'] ? $custom_block['info'] : $custom_block['title']);
- $form['bid'] = array('#type' => 'hidden', '#value' => $block->delta);
-
- return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $custom_block['info'])), 'admin/structure/block', '', t('Delete'), t('Cancel'));
+function block_admin_block_delete($form, &$form_state, $plugin_id, $theme) {
+ $block = block_load($plugin_id);
+ $form['id'] = array('#type' => 'value', '#value' => $plugin_id);
+ $form['theme'] = array('#type' => 'value', '#value' => $theme);
+ $definition = $block->getDefinition();
+ $config = $block->getConfig();
+ $subject = empty($config['subject']) ? $definition['subject'] : $config['subject'];
+ $form['subject'] = array('#type' => 'value', '#value' => $subject);
+
+ return confirm_form($form, t('Are you sure you want to delete the block %name?', array('%name' => $subject)), 'admin/structure/block', '', t('Delete'), t('Cancel'));
}
/**
- * 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()
*/
-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(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'];
}
/**
diff --git a/core/modules/block/block.api.php b/core/modules/block/block.api.php
index b734685..36f8adc 100644
--- a/core/modules/block/block.api.php
+++ b/core/modules/block/block.api.php
@@ -11,356 +11,60 @@
*/
/**
- * Define all blocks provided by the module.
- *
- * This hook declares to Drupal what blocks are provided by your module and can
- * optionally specify initial block configuration settings.
- *
- * In hook_block_info(), each block your module provides is given a unique
- * identifier referred to as "delta" (the array key in the return value). Delta
- * values only need to be unique within your module, and they are used in the
- * following ways:
- * - Passed into the other block hooks in your module as an argument to identify
- * the block being configured or viewed.
- * - Used to construct the default HTML ID of "block-MODULE-DELTA" applied to
- * each block when it is rendered. This ID may then be used for CSS styling or
- * JavaScript programming.
- * - Used to define a theming template suggestion of block__MODULE__DELTA, for
- * advanced theming possibilities.
- * - Used by other modules to identify your block in hook_block_info_alter() and
- * other alter hooks.
- * The values of delta can be strings or numbers, but because of the uses above
- * it is preferable to use descriptive strings whenever possible, and only use a
- * numeric identifier if you have to (for instance if your module allows users
- * to create several similar blocks that you identify within your module code
- * with numeric IDs). The maximum length for delta values is 32 bytes.
- *
- * @return
- * An associative array whose keys define the delta for each block and whose
- * values contain the block descriptions. Each block description is itself an
- * associative array, with the following key-value pairs:
- * - info: (required) The human-readable administrative name of the block.
- * This is used to identify the block on administration screens, and
- * is not displayed to non-administrative users.
- * - cache: (optional) A bitmask describing what kind of caching is
- * appropriate for the block. Drupal provides the following bitmask
- * constants for defining cache granularity:
- * - DRUPAL_CACHE_PER_ROLE (default): The block can change depending on the
- * roles the user viewing the page belongs to.
- * - DRUPAL_CACHE_PER_USER: The block can change depending on the user
- * viewing the page. This setting can be resource-consuming for sites
- * with large number of users, and should only be used when
- * DRUPAL_CACHE_PER_ROLE is not sufficient.
- * - DRUPAL_CACHE_PER_PAGE: The block can change depending on the page
- * being viewed.
- * - DRUPAL_CACHE_GLOBAL: The block is the same for every user on every
- * page where it is visible.
- * - DRUPAL_CACHE_CUSTOM: The module implements its own caching system.
- * - DRUPAL_NO_CACHE: The block should not get cached.
- * - properties: (optional) Array of additional metadata to add to the block.
- * Common properties include:
- * - administrative: Boolean that categorizes this block as usable in an
- * administrative context. This might include blocks that help an
- * administrator approve/deny comments, or view recently created user
- * accounts.
- * - weight: (optional) Initial value for the ordering weight of this block.
- * Most modules do not provide an initial value, and any value provided can
- * be modified by a user on the block configuration screen.
- * - status: (optional) Initial value for block enabled status. (1 = enabled,
- * 0 = disabled). An initial value for 'region' is required for 'status' to
- * take effect.
- * Most modules do not provide an initial value, and any value provided can
- * be modified by a user on the block configuration screen.
- * - region: (optional) Initial value for theme region within which this block
- * is set. If the specified region is not available in a theme, the block
- * will be disabled. The initial value for 'status' must be enabled or the
- * initial region value is ignored.
- * Most modules do not provide an initial value, and any value provided can
- * be modified by a user on the block configuration screen.
- * - visibility: (optional) Initial value for the visibility flag, which tells
- * how to interpret the 'pages' value. Possible values are:
- * - BLOCK_VISIBILITY_NOTLISTED: Show on all pages except listed pages.
- * 'pages' lists the paths where the block should not be shown.
- * - BLOCK_VISIBILITY_LISTED: Show only on listed pages. 'pages' lists the
- * paths where the block should be shown.
- * - BLOCK_VISIBILITY_PHP: Use custom PHP code to determine visibility.
- * 'pages' gives the PHP code to use.
- * Most modules do not provide an initial value for 'visibility' or 'pages',
- * and any value provided can be modified by a user on the block
- * configuration screen.
- * - pages: (optional) See 'visibility' above. A string that contains one or
- * more page paths separated by '\n', '\r', or '\r\n' when 'visibility' is
- * set to BLOCK_VISIBILITY_NOTLISTED or BLOCK_VISIBILITY_LISTED, or custom
- * PHP code when 'visibility' is set to BLOCK_VISIBILITY_PHP. Paths may use
- * '*' as a wildcard (matching any number of characters); '' . t('Use this page to create a new custom block.') . '
'; } - if ($arg[0] == 'admin' && $arg[1] == 'structure' && $arg['2'] == 'block' && (empty($arg[3]) || $arg[3] == 'list')) { - $demo_theme = !empty($arg[4]) ? $arg[4] : variable_get('theme_default', 'stark'); + if ($arg[0] == 'admin' && $arg[1] == 'structure' && $arg['2'] == 'block' && (empty($arg[3]) || $arg[3] == 'list') && empty($arg[5])) { + if (!empty($arg[4])) { + list(, $demo_theme) = explode(':', $arg[4]); + } + else { + $demo_theme = variable_get('theme_default', 'stark'); + } $themes = list_themes(); $output = '' . t('This page provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions. Since not all themes implement the same regions, or display regions in the same way, blocks are positioned on a per-theme basis. Remember that your changes will not be saved until you click the Save blocks button at the bottom of the page. Click the configure link next to each block to configure its specific title and visibility settings.') . '
'; $output .= '' . l(t('Demonstrate block regions (@theme)', array('@theme' => $themes[$demo_theme]->info['name'])), 'admin/structure/block/demo/' . $demo_theme) . '
'; @@ -127,51 +132,40 @@ function block_menu() { $items['admin/structure/block/manage/%/%/delete'] = array( 'title' => 'Delete block', 'page callback' => 'drupal_get_form', - 'page arguments' => array('block_custom_block_delete', 4, 5), + 'page arguments' => array('block_admin_block_delete', 4, 5), 'access arguments' => array('administer blocks'), 'type' => MENU_LOCAL_TASK, 'context' => MENU_CONTEXT_NONE, 'file' => 'block.admin.inc', ); - $items['admin/structure/block/add'] = array( - 'title' => 'Add block', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('block_add_block_form'), - 'access arguments' => array('administer blocks'), - 'type' => MENU_LOCAL_ACTION, - 'file' => 'block.admin.inc', - ); - foreach (list_themes() as $key => $theme) { - $items['admin/structure/block/list/' . $key] = array( - 'title' => check_plain($theme->info['name']), - 'page arguments' => array($key), - 'type' => $key == $default_theme ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, - 'weight' => $key == $default_theme ? -10 : 0, - 'access callback' => '_block_themes_access', - 'access arguments' => array($key), - 'file' => 'block.admin.inc', - ); - if ($key != $default_theme) { - $items['admin/structure/block/list/' . $key . '/add'] = array( - 'title' => 'Add block', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('block_add_block_form'), - 'access arguments' => array('administer blocks'), - 'type' => MENU_LOCAL_ACTION, + // Block administration is actually tied to theme and plugin definition so + // that the plugin can appropriately attach to this url structure. + $themes = list_themes(); + foreach (drupal_container()->get('plugin.manager.system.plugin_ui')->getDefinitions() as $plugin_id => $plugin) { + list($plugin_base, $key) = explode(':', $plugin_id); + if ($plugin_base == 'block_plugin_ui') { + $theme = $themes[$key]; + $items['admin/structure/block/list/' . $plugin_id] = array( + 'title' => check_plain($theme->info['name']), + 'page arguments' => array($key), + 'type' => $key == $default_theme ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK, + 'weight' => $key == $default_theme ? -10 : 0, + 'access callback' => '_block_themes_access', + 'access arguments' => array($key), + 'file' => 'block.admin.inc', + ); + $items['admin/structure/block/demo/' . $key] = array( + 'title' => check_plain($theme->info['name']), + 'page callback' => 'block_admin_demo', + 'page arguments' => array($key), + 'type' => MENU_CALLBACK, + 'access callback' => '_block_themes_access', + 'access arguments' => array($key), + 'theme callback' => '_block_custom_theme', + 'theme arguments' => array($key), 'file' => 'block.admin.inc', ); } - $items['admin/structure/block/demo/' . $key] = array( - 'title' => check_plain($theme->info['name']), - 'page callback' => 'block_admin_demo', - 'page arguments' => array($key), - 'type' => MENU_CALLBACK, - 'access callback' => '_block_themes_access', - 'access arguments' => array($key), - 'theme callback' => '_block_custom_theme', - 'theme arguments' => array($key), - 'file' => 'block.admin.inc', - ); } return $items; } @@ -212,53 +206,6 @@ function _block_custom_theme($theme = NULL) { } /** - * Implements hook_block_info(). - */ -function block_block_info() { - $blocks = array(); - - $result = db_query('SELECT bid, info FROM {block_custom} ORDER BY info'); - foreach ($result as $block) { - $blocks[$block->bid]['info'] = $block->info; - // Not worth caching. - $blocks[$block->bid]['cache'] = DRUPAL_NO_CACHE; - } - return $blocks; -} - -/** - * Implements hook_block_configure(). - */ -function block_block_configure($delta = 0) { - if ($delta) { - $custom_block = block_custom_block_get($delta); - } - else { - $custom_block = array(); - } - return block_custom_block_form($custom_block); -} - -/** - * Implements hook_block_save(). - */ -function block_block_save($delta = 0, $edit = array()) { - block_custom_block_save($edit, $delta); -} - -/** - * Implements hook_block_view(). - * - * Generates the administrator-defined blocks for display. - */ -function block_block_view($delta = '') { - $block = db_query('SELECT body, format FROM {block_custom} WHERE bid = :bid', array(':bid' => $delta))->fetchObject(); - $data['subject'] = NULL; - $data['content'] = check_markup($block->body, $block->format, '', TRUE); - return $data; -} - -/** * Implements hook_page_build(). * * Renders blocks into their regions. @@ -343,7 +290,6 @@ function block_get_blocks_by_region($region) { * A renderable array. */ function _block_get_renderable_region($list = array()) { - $weight = 0; $build = array(); // Block caching is not compatible with node_access modules. We also // preserve the submission of forms in blocks, by fetching from cache @@ -356,23 +302,27 @@ function _block_get_renderable_region($list = array()) { !in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD')); foreach ($list as $key => $block) { + $config = $block->getConfig(); + $definition = $block->getDefinition(); $build[$key] = array( '#block' => $block, - '#weight' => ++$weight, + '#weight' => (int) $config['weight'], '#theme_wrappers' => array('block'), ); - if ($not_cacheable || in_array($block->cache, array(DRUPAL_NO_CACHE, DRUPAL_CACHE_CUSTOM))) { + if ($not_cacheable || in_array($config['cache'], array(DRUPAL_NO_CACHE, DRUPAL_CACHE_CUSTOM))) { // Non-cached blocks get built immediately. Provides more content // that can be easily manipulated during hook_page_alter(). $build[$key] = _block_get_renderable_block($build[$key]); } else { + $key_components = explode('.', $key); + $id = array_pop($key_components); $build[$key] += array( '#pre_render' => array('_block_get_renderable_block'), '#cache' => array( - 'keys' => array($block->module, $block->delta), - 'granularity' => $block->cache, + 'keys' => array($id, $config['module']), + 'granularity' => $config['cache'], 'bin' => 'block', 'tags' => array('content' => TRUE), ), @@ -384,16 +334,16 @@ function _block_get_renderable_region($list = array()) { // skip the help block, since we assume that most users do not need or want // to perform contextual actions on the help block, and the links needlessly // draw attention on it. - if ($key != 'system_main' && $key != 'system_help') { - $build[$key]['#contextual_links']['block'] = array('admin/structure/block/manage', array($block->module, $block->delta)); + if ($definition['class'] != 'Drupal\\system\\Plugin\\block\\block\\SystemHelpBlock' && $definition['class'] != 'Drupal\\system\\Plugin\\block\\block\\SystemMainBlock') { + global $theme; + $build[$key]['#contextual_links']['block'] = array('admin/structure/block/manage', array($key, $theme)); } } - $build['#sorted'] = TRUE; return $build; } /** - * Updates the 'block' DB table with the blocks currently exported by modules. + * Returns an array of block class instances by theme. * * @param $theme * The theme to rehash blocks for. If not provided, defaults to the currently @@ -403,252 +353,35 @@ function _block_get_renderable_region($list = array()) { * Blocks currently exported by modules. */ function _block_rehash($theme = NULL) { - global $theme_key; - - drupal_theme_initialize(); - if (!isset($theme)) { - // If theme is not specifically set, rehash for the current theme. - $theme = $theme_key; - } - $regions = system_region_list($theme); - - // These are the blocks the function will return. $blocks = array(); - // These are the blocks defined by code and modified by the database. - $current_blocks = array(); - // These are {block}.bid values to be kept. - $bids = array(); - $or = db_or(); - // Gather the blocks defined by modules. - foreach (module_implements('block_info') as $module) { - $module_blocks = module_invoke($module, 'block_info'); - foreach ($module_blocks as $delta => $block) { - // Compile a condition to retrieve this block from the database. - $condition = db_and() - ->condition('module', $module) - ->condition('delta', $delta); - $or->condition($condition); - // Add identifiers. - $block['module'] = $module; - $block['delta'] = $delta; - $block['theme'] = $theme; - $current_blocks[$module][$delta] = $block; - } - } - // Save the blocks defined in code for alter context. - $code_blocks = $current_blocks; - $database_blocks = db_select('block', 'b') - ->fields('b') - ->condition($or) - ->condition('theme', $theme) - ->execute(); - foreach ($database_blocks as $block) { - // Preserve info which is not in the database. - $block->info = $current_blocks[$block->module][$block->delta]['info']; - // The cache mode can only by set from hook_block_info(), so that has - // precedence over the database's value. - if (isset($current_blocks[$block->module][$block->delta]['cache'])) { - $block->cache = $current_blocks[$block->module][$block->delta]['cache']; + $instances = array(); + $theme = $theme ? $theme : variable_get('theme_default', 'stark'); + $block_configs = config_get_storage_names_with_prefix('plugin.core.block.' . $theme); + $regions = system_region_list($theme); + foreach ($block_configs as $config) { + $blocks[$config] = block_load($config); + $config = config($config); + $region = $config->get('region'); + $status = $config->get('status'); + // Disable blocks in invalid regions. + if (!empty($region) && $region != BLOCK_REGION_NONE && !isset($regions[$region]) && $status == 1) { + drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $config->get('id'), '%region' => $region)), 'warning'); + // Disabled modules are moved into the BLOCK_REGION_NONE later so no + // need to move the block to another region. + $config->set('status', 0); + $config->save(); } - // Blocks stored in the database override the blocks defined in code. - $current_blocks[$block->module][$block->delta] = get_object_vars($block); - // Preserve this block. - $bids[$block->bid] = $block->bid; - } - drupal_alter('block_info', $current_blocks, $theme, $code_blocks); - foreach ($current_blocks as $module => $module_blocks) { - foreach ($module_blocks as $delta => $block) { - if (!isset($block['pages'])) { - // {block}.pages is type 'text', so it cannot have a - // default value, and not null, so we need to provide - // value if the module did not. - $block['pages'] = ''; - } - // Make sure weight is set. - if (!isset($block['weight'])) { - $block['weight'] = 0; - } - if (!empty($block['region']) && $block['region'] != BLOCK_REGION_NONE && !isset($regions[$block['region']]) && $block['status'] == 1) { - drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $block['info'], '%region' => $block['region'])), 'warning'); - // Disabled modules are moved into the BLOCK_REGION_NONE later so no - // need to move the block to another region. - $block['status'] = 0; - } - // Set region to none if not enabled and make sure status is set. - if (empty($block['status'])) { - $block['status'] = 0; - $block['region'] = BLOCK_REGION_NONE; - } - // There is no point saving disabled blocks. Still, we need to save them - // because the 'title' attribute is saved to the {blocks} table. - if (isset($block['bid'])) { - // If the block has a bid property, it comes from the database and - // the record needs to be updated, so set the primary key to 'bid' - // before passing to drupal_write_record(). - $primary_keys = array('bid'); - // Remove a block from the list of blocks to keep if it became disabled. - unset($bids[$block['bid']]); - } - else { - $primary_keys = array(); - } - drupal_write_record('block', $block, $primary_keys); - // Add to the list of blocks we return. - $blocks[] = $block; + // Set region to none if not enabled and make sure status is set. + if (empty($status)) { + $config->set('region', BLOCK_REGION_NONE); + $config->set('status', 0); + $config->save(); } } - if ($bids) { - // Remove disabled that are no longer defined by the code from the - // database. - db_delete('block') - ->condition('bid', $bids, 'NOT IN') - ->condition('theme', $theme) - ->execute(); - } return $blocks; } /** - * Returns information from database about a user-created (custom) block. - * - * @param $bid - * ID of the block to get information for. - * - * @return - * Associative array of information stored in the database for this block. - * Array keys: - * - bid: Block ID. - * - info: Block description. - * - body: Block contents. - * - format: Filter ID of the filter format for the body. - */ -function block_custom_block_get($bid) { - return db_query("SELECT * FROM {block_custom} WHERE bid = :bid", array(':bid' => $bid))->fetchAssoc(); -} - -/** - * Form constructor for the custom block form. - * - * @param $edit - * (optional) An associative array of information retrieved by - * block_custom_get_block() if an existing block is being edited, or an empty - * array otherwise. Defaults to array(). - * - * @ingroup forms - */ -function block_custom_block_form($edit = array()) { - $edit += array( - 'info' => '', - 'body' => '', - ); - $form['info'] = array( - '#type' => 'textfield', - '#title' => t('Block description'), - '#default_value' => $edit['info'], - '#maxlength' => 64, - '#description' => t('A brief description of your block. Used on the Blocks administration page.', array('@overview' => url('admin/structure/block'))), - '#required' => TRUE, - '#weight' => -18, - ); - $form['body_field']['#weight'] = -17; - $form['body_field']['body'] = array( - '#type' => 'text_format', - '#title' => t('Block body'), - '#default_value' => $edit['body'], - '#format' => isset($edit['format']) ? $edit['format'] : NULL, - '#rows' => 15, - '#description' => t('The content of the block as shown to the user.'), - '#required' => TRUE, - '#weight' => -17, - ); - - return $form; -} - -/** - * Saves a user-created block in the database. - * - * @param $edit - * Associative array of fields to save. Array keys: - * - info: Block description. - * - body: Associative array of body value and format. Array keys: - * - value: Block contents. - * - format: Filter ID of the filter format for the body. - * @param $delta - * Block ID of the block to save. - * - * @return - * Always returns TRUE. - */ -function block_custom_block_save($edit, $delta) { - db_update('block_custom') - ->fields(array( - 'body' => $edit['body']['value'], - 'info' => $edit['info'], - 'format' => $edit['body']['format'], - )) - ->condition('bid', $delta) - ->execute(); - return TRUE; -} - -/** - * Implements hook_form_FORM_ID_alter() for user_profile_form(). - */ -function block_form_user_profile_form_alter(&$form, &$form_state) { - $account = $form_state['controller']->getEntity($form_state); - $rids = array_keys($account->roles); - $result = db_query("SELECT DISTINCT b.* FROM {block} b LEFT JOIN {block_role} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom <> 0 AND (r.rid IN (:rids) OR r.rid IS NULL) ORDER BY b.weight, b.module", array(':rids' => $rids)); - $account_data = drupal_container()->get('user.data')->get('block', $account->id(), 'block'); - - $blocks = array(); - foreach ($result as $block) { - $data = module_invoke($block->module, 'block_info'); - if ($data[$block->delta]['info']) { - $blocks[$block->module][$block->delta] = array( - '#type' => 'checkbox', - '#title' => check_plain($data[$block->delta]['info']), - '#default_value' => isset($account_data[$block->module][$block->delta]) ? $account_data[$block->module][$block->delta] : ($block->custom == 1), - ); - } - } - // Only display the form element if there are any personalizable blocks. - if ($blocks) { - $form['block'] = array( - '#type' => 'details', - '#title' => t('Personalize blocks'), - '#description' => t('Blocks consist of content or information that complements the main content of the page. Enable or disable optional blocks using the checkboxes below.'), - '#weight' => 3, - '#collapsible' => TRUE, - '#tree' => TRUE, - ); - $form['block'] += $blocks; - } -} - -/** - * Implements hook_field_extra_fields(). - */ -function block_field_extra_fields() { - $extra['user']['user']['form']['block'] = array( - 'label' => t('Personalize blocks'), - 'description' => t('Block module form element.'), - 'weight' => 3, - ); - - return $extra; -} - -/** - * Implements hook_user_update(). - */ -function block_user_update($account) { - if (isset($account->block)) { - drupal_container()->get('user.data')->set('block', $account->id(), 'block', $account->block); - } -} - -/** * Initializes blocks for enabled themes. * * @param $theme_list @@ -673,20 +406,28 @@ function block_themes_enabled($theme_list) { */ function block_theme_initialize($theme) { // Initialize theme's blocks if none already registered. - $has_blocks = (bool) db_query_range('SELECT 1 FROM {block} WHERE theme = :theme', 0, 1, array(':theme' => $theme))->fetchField(); + $has_blocks = config_get_storage_names_with_prefix('plugin.core.block.' . $theme); if (!$has_blocks) { $default_theme = variable_get('theme_default', 'stark'); // Apply only to new theme's visible regions. $regions = system_region_list($theme, REGIONS_VISIBLE); - $result = db_query("SELECT * FROM {block} WHERE theme = :theme", array(':theme' => $default_theme), array('fetch' => PDO::FETCH_ASSOC)); - foreach ($result as $block) { - // If the region isn't supported by the theme, assign the block to the theme's default region. - if ($block['status'] && !isset($regions[$block['region']])) { - $block['region'] = system_default_region($theme); + $default_theme_blocks = config_get_storage_names_with_prefix('plugin.core.block.' . $default_theme); + foreach ($default_theme_blocks as $config_id) { + $block_config = config($config_id)->get(); + $machine_name = explode('.', $config_id); + $machine_name = array_pop($machine_name); + $new_config_id = 'plugin.core.block.' . $theme . '.' . $machine_name; + $new_block = config($new_config_id); + // If the region isn't supported by the theme, assign the block to the + // theme's default region. + if (!isset($regions[$block_config['region']])) { + $new_block->set('region', system_default_region($theme)); + unset($block_config['region']); + } + foreach ($block_config as $key => $value) { + $new_block->set($key, $value); } - $block['theme'] = $theme; - unset($block['bid']); - drupal_write_record('block', $block); + $new_block->save(); } } } @@ -698,14 +439,11 @@ function block_theme_initialize($theme) { * The name of a region. * * @return - * An array of block objects, indexed with the module name and block delta - * concatenated with an underscore, thus: MODULE_DELTA. If you are displaying - * your blocks in one or two sidebars, you may check whether this array is - * empty to see how many columns are going to be displayed. + * An array of block objects, indexed with the CMI key that represents the + * configuration. If you are displaying your blocks in one or two sidebars, + * you may check whether this array is empty to see how many columns are + * going to be displayed. * - * @todo - * Now that the block table has a primary key, we should use that as the - * array key instead of MODULE_DELTA. */ function block_list($region) { $blocks = &drupal_static(__FUNCTION__); @@ -725,178 +463,43 @@ function block_list($region) { /** * Loads a block object from the database. * - * @param $module - * Name of the module that implements the block to load. - * @param $delta - * Unique ID of the block within the context of $module. Pass NULL to return - * an empty block object for $module. + * @param string $plugin_id + * The plugin id to load. + * @param array $conf + * An optional configuration array for creating a block instance from php + * instead of relying on configuration xml. * * @return * A block object. */ -function block_load($module, $delta) { - if (isset($delta)) { - $block = db_query('SELECT * FROM {block} WHERE module = :module AND delta = :delta', array(':module' => $module, ':delta' => $delta))->fetchObject(); - } - - // If the block does not exist in the database yet return a stub block - // object. - if (empty($block)) { - $block = new stdClass(); - $block->module = $module; - $block->delta = $delta; +function block_load($plugin_id, array $conf = array()) { + $manager = drupal_container()->get('plugin.manager.block'); + if (!$block = $manager->getInstance(array('config' => $plugin_id))) { + $block = $manager->createInstance($plugin_id, $conf); } - return $block; } /** - * Loads blocks' information from the database. + * Loads blocks' information from the configuration management system. * * @return * An array of blocks grouped by region. */ function _block_load_blocks() { - global $theme_key; - - $query = db_select('block', 'b'); - $query->addField('b', 'title', 'subject'); - $result = $query - ->fields('b') - ->condition('b.theme', $theme_key) - ->condition('b.status', 1) - ->orderBy('b.region') - ->orderBy('b.weight') - ->orderBy('b.module') - ->addTag('block_load') - ->addTag('translatable') - ->execute(); - - $block_info = $result->fetchAllAssoc('bid'); - // Allow modules to modify the block list. - drupal_alter('block_list', $block_info); - + global $theme; $blocks = array(); - foreach ($block_info as $block) { - $blocks[$block->region]["{$block->module}_{$block->delta}"] = $block; + $instances = config_get_storage_names_with_prefix('plugin.core.block.' . $theme); + $manager = drupal_container()->get('plugin.manager.block'); + foreach ($instances as $plugin_id) { + $block = $manager->getInstance(array('config' => $plugin_id)); + $config = $block->getConfig(); + $blocks[$config['region']]["$plugin_id"] = $block; } return $blocks; } /** - * Implements hook_block_list_alter(). - * - * Checks the page, user role, and user-specific visibility settings. - * Removes the block if the visibility conditions are not met. - */ -function block_block_list_alter(&$blocks) { - global $user, $theme_key; - - // Build an array of roles for each block. - $block_roles = array(); - $result = db_query('SELECT module, delta, rid FROM {block_role}'); - foreach ($result as $record) { - $block_roles[$record->module][$record->delta][] = $record->rid; - } - - // Build an array of langcodes allowed per block. - $result = db_query('SELECT module, delta, type, langcode FROM {block_language}'); - $block_langcodes = array(); - foreach ($result as $record) { - $block_langcodes[$record->module][$record->delta][$record->type][$record->langcode] = TRUE; - } - - if ($user->uid) { - $user_data = drupal_container()->get('user.data')->get('block', $user->uid, 'block'); - } - - foreach ($blocks as $key => $block) { - if (!isset($block->theme) || !isset($block->status) || $block->theme != $theme_key || $block->status != 1) { - // This block was added by a contrib module, leave it in the list. - continue; - } - - // If a block has no roles associated, it is displayed for every role. - // For blocks with roles associated, if none of the user's roles matches - // the settings from this block, remove it from the block list. - if (isset($block_roles[$block->module][$block->delta]) && !array_intersect($block_roles[$block->module][$block->delta], array_keys($user->roles))) { - // No match. - unset($blocks[$key]); - continue; - } - - // Use the user's block visibility setting, if necessary. - if ($block->custom != BLOCK_CUSTOM_FIXED) { - if ($user->uid && isset($user_data[$block->module][$block->delta])) { - $enabled = $user_data[$block->module][$block->delta]; - } - else { - $enabled = ($block->custom == BLOCK_CUSTOM_ENABLED); - } - } - else { - $enabled = TRUE; - } - - // Limited visibility blocks must list at least one page. - if ($block->visibility == BLOCK_VISIBILITY_LISTED && empty($block->pages)) { - $enabled = FALSE; - } - - if (!$enabled) { - unset($blocks[$key]); - continue; - } - - // Match path if necessary. - if ($block->pages) { - // Convert path to lowercase. This allows comparison of the same path - // with different case. Ex: /Page, /page, /PAGE. - $pages = drupal_strtolower($block->pages); - if ($block->visibility < BLOCK_VISIBILITY_PHP) { - // Compare the lowercase path alias (if any) and internal path. - $path = current_path(); - $path_alias = drupal_strtolower(drupal_container()->get('path.alias_manager')->getPathAlias($path)); - $page_match = drupal_match_path($path_alias, $pages) || (($path != $path_alias) && drupal_match_path($path, $pages)); - // When $block->visibility has a value of 0 (BLOCK_VISIBILITY_NOTLISTED), - // the block is displayed on all pages except those listed in $block->pages. - // When set to 1 (BLOCK_VISIBILITY_LISTED), it is displayed only on those - // pages listed in $block->pages. - $page_match = !($block->visibility xor $page_match); - } - elseif (module_exists('php')) { - $page_match = php_eval($block->pages); - } - else { - $page_match = FALSE; - } - } - else { - $page_match = TRUE; - } - if (!$page_match) { - unset($blocks[$key]); - continue; - } - - // Language visibility settings. - // No language setting for this block, leave it in the list. - if (!isset($block_langcodes[$block->module][$block->delta])) { - continue; - } - foreach ($block_langcodes[$block->module][$block->delta] as $language_type => $langcodes) { - if (isset($langcodes[language($language_type)->langcode])) { - // Found a language type - langcode combination in the configuration - // that is applicable to the current request. - continue 2; - } - } - // Had language configuration but none matched. - unset($blocks[$key]); - } -} - -/** * Builds the content and subject for a block. * * For cacheable blocks, this is called during #pre_render. @@ -909,50 +512,47 @@ function block_block_list_alter(&$blocks) { */ function _block_get_renderable_block($element) { $block = $element['#block']; - - // Render the block content if it has not been created already. - if (!isset($block->content)) { - $array = module_invoke($block->module, 'block_view', $block->delta); - - // Allow modules to modify the block before it is viewed, via either - // hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter(). - drupal_alter(array('block_view', "block_view_{$block->module}_{$block->delta}"), $array, $block); - - if (empty($array['content'])) { - // Blocks without content should emit no markup at all. - $element += array( - '#access' => FALSE, - '#printed' => TRUE, - ); - } - elseif (isset($array) && is_array($array)) { - foreach ($array as $k => $v) { - $block->$k = $v; + // Don't bother to build blocks that aren't accessible. + if ($element['#access'] = $block->accessWrapper()) { + $build = block_build($block); + if ($build) { + if (isset($build['#title'])) { + $element['#title'] = $build['#title']; } + $element += $build; } - } - - if (isset($block->content) && $block->content) { - // Normalize to the drupal_render() structure. - if (is_string($block->content)) { - $block->content = array('#markup' => $block->content); - } - // Override default block title if a custom display title is present. - if ($block->title) { - // Check plain here to allow module generated titles to keep any - // markup. - $block->subject = $block->title == 'TRUE
(experts only)'));
+ $title = t('Pages or PHP code');
+ $description .= ' ' . t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.', array('%php' => ''));
+ }
+ else {
+ $title = t('Pages');
+ }
+ $form['visibility']['path']['visibility'] = array(
+ '#type' => 'radios',
+ '#title' => t('Show block on specific pages'),
+ '#options' => $options,
+ '#default_value' => !empty($this->configuration['visibility']['path']['visibility']) ? $this->configuration['visibility']['path']['visibility'] : BLOCK_VISIBILITY_NOTLISTED,
+ );
+ $form['visibility']['path']['pages'] = array(
+ '#type' => 'textarea',
+ '#title' => '' . $title . '',
+ '#default_value' => !empty($this->configuration['visibility']['path']['pages']) ? $this->configuration['visibility']['path']['pages'] : '',
+ '#description' => $description,
+ );
+ }
+
+ // Configure the block visibility per language.
+ if (module_exists('language') && language_multilingual()) {
+ $configurable_language_types = language_types_get_configurable();
+
+ // Fetch languages.
+ $languages = language_list(LANGUAGE_ALL);
+ foreach ($languages as $language) {
+ // @todo $language->name is not wrapped with t(), it should be replaced
+ // by CMI translation implementation.
+ $langcodes_options[$language->langcode] = $language->name;
+ }
+ $form['visibility']['language'] = array(
+ '#type' => 'details',
+ '#title' => t('Languages'),
+ '#collapsed' => TRUE,
+ '#group' => 'visibility',
+ '#weight' => 5,
+ );
+ // If there are multiple configurable language types, let the user pick
+ // which one should be applied to this visibility setting. This way users
+ // can limit blocks by interface language or content language for exmaple.
+ $language_types = language_types_info();
+ $language_type_options = array();
+ foreach ($configurable_language_types as $type_key) {
+ $language_type_options[$type_key] = $language_types[$type_key]['name'];
+ }
+ $form['visibility']['language']['language_type'] = array(
+ '#type' => 'radios',
+ '#title' => t('Language type'),
+ '#options' => $language_type_options,
+ '#default_value' => !empty($this->configuration['visibility']['language']['language_type']) ? $this->configuration['visibility']['language']['language_type'] : $configurable_language_types[0],
+ '#access' => count($language_type_options) > 1,
+ );
+ $form['visibility']['language']['langcodes'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Show this block only for specific languages'),
+ '#default_value' => !empty($this->configuration['visibility']['language']['langcodes']) ? $this->configuration['visibility']['language']['langcodes'] : array(),
+ '#options' => $langcodes_options,
+ '#description' => t('Show this block only for the selected language(s). If you select no languages, the block will be visibile in all languages.'),
+ );
+ }
+
+ // Per-role visibility.
+ $role_options = array_map('check_plain', user_roles());
+ $form['visibility']['role'] = array(
+ '#type' => 'details',
+ '#title' => t('Roles'),
+ '#collapsed' => TRUE,
+ '#group' => 'visibility',
+ '#weight' => 10,
+ );
+ $form['visibility']['role']['roles'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Show block for specific roles'),
+ '#default_value' => !empty($this->configuration['visibility']['role']['roles']) ? $this->configuration['visibility']['role']['roles'] : array(),
+ '#options' => $role_options,
+ '#description' => t('Show this block only for the selected role(s). If you select no roles, the block will be visible to all users.'),
+ );
+
+ $form += $this->configure($form, $form_state);
+
+ $form['actions'] = array('#type' => 'actions');
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save block'),
+ );
+
+ return $form;
+ }
+
+ /**
+ * Implements \Drupal\block\BlockInterface::configure().
+ */
+ public function configure($form, &$form_state) {
+ return array();
+ }
+
+ /**
+ * Implements \Drupal\block\BlockInterface::configureValidateWrapper().
+ */
+ public function configureValidateWrapper($form, &$form_state) {
+ if (empty($form['settings']['machine_name']['#disabled'])) {
+ if (preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['machine_name'])) {
+ form_set_error('machine_name', t('Block name must be alphanumeric or underscores only.'));
+ }
+ if (in_array('plugin.core.block.' . $form_state['values']['machine_name'], config_get_storage_names_with_prefix('plugin.core.block'))) {
+ form_set_error('machine_name', t('Block name must be unique.'));
+ }
+ }
+ else {
+ $config_id = explode('.', $form_state['values']['machine_name']);
+ $form_state['values']['machine_name'] = array_pop($config_id);
+ }
+ if ($form_state['values']['module'] == 'block') {
+ $custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE bid <> :bid AND info = :info', 0, 1, array(
+ ':bid' => $form_state['values']['delta'],
+ ':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_state['values']['visibility']['role']['roles'] = array_filter($form_state['values']['visibility']['role']['roles']);
+ $this->configureValidate($form, $form_state);
+ }
+
+ /**
+ * Implements \Drupal\block\BlockInterface::configureValidate().
+ */
+ public function configureValidate($form, &$form_state) {}
+
+ /**
+ * Implements \Drupal\block\BlockInterface::configureSubmitWrapper().
+ */
+ public function configureSubmitWrapper($form, &$form_state) {
+ if (!form_get_errors()) {
+ $transaction = db_transaction();
+ try {
+ $keys = array(
+ 'visibility' => 'visibility',
+ 'pages' => 'pages',
+ 'custom' => 'custom',
+ 'title' => 'subject',
+ 'module' => 'module',
+ 'region' => 'region',
+ );
+ foreach ($keys as $key => $new_key) {
+ if (isset($form_state['values'][$key])) {
+ $this->configuration[$new_key] = $form_state['values'][$key];
+ }
+ }
+ }
+ catch (Exception $e) {
+ $transaction->rollback();
+ watchdog_exception('block', $e);
+ throw $e;
+ }
+ if (empty($this->configuration['weight'])) {
+ $this->configuration['weight'] = 0;
+ }
+ drupal_set_message(t('The block configuration has been saved.'));
+ drupal_flush_all_caches();
+ $this->configureSubmit($form, $form_state);
+ }
+ }
+
+ /**
+ * Implements \Drupal\block\BlockInterface::configureSubmit().
+ */
+ public function configureSubmit($form, &$form_state) {
+ }
+
+}
diff --git a/core/modules/block/lib/Drupal/block/BlockBundle.php b/core/modules/block/lib/Drupal/block/BlockBundle.php
new file mode 100644
index 0000000..4ad19a5
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/BlockBundle.php
@@ -0,0 +1,26 @@
+register('plugin.manager.block', 'Drupal\block\Plugin\Type\BlockManager');
+ }
+
+}
diff --git a/core/modules/block/lib/Drupal/block/BlockInterface.php b/core/modules/block/lib/Drupal/block/BlockInterface.php
new file mode 100644
index 0000000..c152ea2
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/BlockInterface.php
@@ -0,0 +1,91 @@
+derivatives) && !empty($this->derivatives[$derivative_id])) {
+ return $this->derivatives[$derivative_id];
+ }
+ $this->getDerivativeDefinitions($base_plugin_definition);
+ return $this->derivatives[$derivative_id];
+ }
+
+ /**
+ * Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinitions().
+ */
+ public function getDerivativeDefinitions(array $base_plugin_definition) {
+ foreach (list_themes() as $key => $theme) {
+ $this->derivatives[$key] = $base_plugin_definition;
+ }
+ return $this->derivatives;
+ }
+
+}
diff --git a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php
new file mode 100644
index 0000000..bf89cc4
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php
@@ -0,0 +1,30 @@
+discovery = new AlterDecorator(new DerivativeDiscoveryDecorator(new AnnotatedClassDiscovery('block', 'block')), 'block');
+ $this->factory = new DefaultFactory($this);
+ $this->mapper = new ConfigMapper($this);
+ }
+
+}
diff --git a/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php b/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php
new file mode 100644
index 0000000..9fc2534
--- /dev/null
+++ b/core/modules/block/lib/Drupal/block/Plugin/system/plugin_ui/BlockPluginUI.php
@@ -0,0 +1,107 @@
+getPluginId());
+ $form['theme'] = array(
+ '#type' => 'value',
+ '#value' => $theme,
+ );
+ return parent::form($form, $form_state, $facet);
+ }
+
+ /**
+ * Overrides \Drupal\system\Plugin\PluginUIBase::excludeDefinitions().
+ */
+ public function excludeDefinitions($definitions) {
+ return array_filter($definitions, function ($definition) {
+ return empty($definition['custom']);
+ });
+ }
+
+ /**
+ * Overrides \Drupal\system\Plugin\PluginUIBase::formSubmit().
+ */
+ public function formSubmit($form, &$form_state) {
+ $form_state['redirect'] = 'admin/structure/block/manage/' . $form_state['values']['block'] . '/' . $form_state['values']['theme'];
+ }
+
+ /**
+ * Overrides \Drupal\system\Plugin\PluginUIBase::access().
+ */
+ public function access() {
+ list($plugin, $theme) = explode(':', $this->getPluginId());
+ return _block_themes_access($theme);
+ }
+
+ /**
+ * Overrides \Drupal\system\Plugin\PluginUIBase::tableHeader().
+ */
+ public function tableHeader() {
+ return array(t('Subject'), t('Operations'));
+ }
+
+ /**
+ * Overrides \Drupal\system\Plugin\PluginUIBase::row().
+ */
+ public function row($display_plugin_id, $display_plugin_definition) {
+ $plugin_definition = $this->getDefinition();
+ list($plugin, $theme) = explode(':', $this->getPluginId());
+ $row = array();
+ $row[] = $display_plugin_definition['subject'];
+ $row[] = array('data' => array(
+ '#type' => 'operations',
+ '#links' => array(
+ 'configure' => array(
+ 'title' => $plugin_definition['link_title'],
+ 'href' => $plugin_definition['config_path'] . '/' . $display_plugin_id . '/' . $theme,
+ ),
+ ),
+ ));
+ return $row;
+ }
+
+}
diff --git a/core/modules/block/lib/Drupal/block/Plugin/views/display/Block.php b/core/modules/block/lib/Drupal/block/Plugin/views/display/Block.php
index 584ac00..998fb6f 100644
--- a/core/modules/block/lib/Drupal/block/Plugin/views/display/Block.php
+++ b/core/modules/block/lib/Drupal/block/Plugin/views/display/Block.php
@@ -78,7 +78,7 @@ public function execute() {
// Prior to this being called, the $view should already be set to this
// display, and arguments should be set on the view.
$info['content'] = $this->view->render();
- $info['subject'] = filter_xss_admin($this->view->getTitle());
+ $info['#title'] = filter_xss_admin($this->view->getTitle());
if (!empty($this->view->result) || $this->getOption('empty') || !empty($this->view->style_plugin->definition['even empty'])) {
return $info;
}
@@ -138,7 +138,7 @@ protected function blockCachingModes() {
* Provide a single method to figure caching type, keeping a sensible default
* for when it's unset.
*/
- protected function getCacheType() {
+ public function getCacheType() {
$cache_type = $this->getOption('block_caching');
if (empty($cache_type)) {
$cache_type = DRUPAL_NO_CACHE;
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockAdminThemeTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockAdminThemeTest.php
index c3a220f..8c64ac8 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockAdminThemeTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockAdminThemeTest.php
@@ -38,14 +38,14 @@ function testAdminTheme() {
$this->drupalLogin($admin_user);
// Ensure that access to block admin page is denied when theme is disabled.
- $this->drupalGet('admin/structure/block/list/bartik');
+ $this->drupalGet('admin/structure/block/list/block_plugin_ui:bartik');
$this->assertResponse(403);
// Enable admin theme and confirm that tab is accessible.
theme_enable(array('bartik'));
$edit['admin_theme'] = 'bartik';
$this->drupalPost('admin/appearance', $edit, t('Save configuration'));
- $this->drupalGet('admin/structure/block/list/bartik');
+ $this->drupalGet('admin/structure/block/list/block_plugin_ui:bartik');
$this->assertResponse(200);
}
}
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php
index 3a5776c..6bbccdf 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockCacheTest.php
@@ -49,8 +49,12 @@ function setUp() {
$this->normal_user_alt->save();
// Enable our test block.
- $edit['blocks[block_test_test_cache][region]'] = 'sidebar_first';
- $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
+ $this->theme = variable_get('theme_default', 'stark');
+ $block = array();
+ $block['machine_name'] = $this->randomName(8);
+ $block['region'] = 'sidebar_first';
+ $this->block = $block;
+ $this->drupalPost('admin/structure/block/manage/test_cache/' . $this->theme, $block, t('Save block'));
}
/**
@@ -192,14 +196,17 @@ function testCachePerPage() {
* Private helper method to set the test block's cache mode.
*/
private function setCacheMode($cache_mode) {
- db_update('block')
- ->fields(array('cache' => $cache_mode))
- ->condition('module', 'block_test')
- ->execute();
-
- $current_mode = db_query("SELECT cache FROM {block} WHERE module = 'block_test'")->fetchField();
- if ($current_mode != $cache_mode) {
- $this->fail(t('Unable to set cache mode to %mode. Current mode: %current_mode', array('%mode' => $cache_mode, '%current_mode' => $current_mode)));
+ $block = $this->block;
+ $block['config_id'] = 'plugin.core.block.' . $this->theme . '.' . $block['machine_name'];
+ $block_config = config($block['config_id']);
+ $block_config->set('cache', $cache_mode);
+ $block_config->save();
+
+ $instance = block_load($block['config_id']);
+ $config = $instance->getConfig();
+ if ($config['cache'] != $cache_mode) {
+ $this->fail(t('Unable to set cache mode to %mode. Current mode: %current_mode', array('%mode' => $cache_mode, '%current_mode' => $config['cache'])));
}
+ $this->assertEqual($config['cache'], $cache_mode, t("Test block's database entry updated to DRUPAL_NO_CACHE."));
}
}
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php
index af5acb9..ecfade3 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockHiddenRegionTest.php
@@ -14,6 +14,7 @@
*/
class BlockHiddenRegionTest extends WebTestBase {
+ protected $admin_user;
/**
* Modules to enable.
*
@@ -32,30 +33,31 @@ public static function getInfo() {
function setUp() {
parent::setUp();
- // Enable Search block in default theme.
- db_merge('block')
- ->key(array(
- 'module' => 'search',
- 'delta' => 'form',
- 'theme' => variable_get('theme_default', 'stark'),
- ))
- ->fields(array(
- 'status' => 1,
- 'weight' => -1,
- 'region' => 'sidebar_first',
- 'pages' => '',
- 'cache' => -1,
- ))
- ->execute();
+ // Create administrative user.
+ $this->admin_user = $this->drupalCreateUser(array(
+ 'administer blocks',
+ 'administer themes',
+ 'search content',
+ )
+ );
+
+ $this->drupalLogin($this->admin_user);
+
+ $default_theme = variable_get('theme_default', 'stark');
+
+ $block['machine_name'] = $this->randomName();
+ $block['region'] = 'sidebar_first';
+ $block['title'] = $this->randomName();
+ $this->drupalPost('admin/structure/block/manage/search_form_block/' . $default_theme, $block, t('Save block'));
+ $this->assertText('The block configuration has been saved.', 'Block was saved');
}
/**
* Tests that hidden regions do not inherit blocks when a theme is enabled.
*/
- function testBlockNotInHiddenRegion() {
- // Create administrative user.
- $admin_user = $this->drupalCreateUser(array('administer blocks', 'administer themes', 'search content'));
- $this->drupalLogin($admin_user);
+ public function testBlockNotInHiddenRegion() {
+
+ $this->drupalLogin($this->admin_user);
// Ensure that the search form block is displayed.
$this->drupalGet('');
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php
index 705bc76..91cc7c1 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockHtmlIdTest.php
@@ -14,6 +14,8 @@
*/
class BlockHtmlIdTest extends WebTestBase {
+ protected $adminUser;
+
/**
* Modules to enable.
*
@@ -33,16 +35,19 @@ function setUp() {
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();
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'));
}
/**
@@ -50,6 +55,6 @@ function setUp() {
*/
function testHtmlId() {
$this->drupalGet('');
- $this->assertRaw('block-block-test-test-html-id', 'HTML id for test block is valid.');
+ $this->assertRaw('id="block-test-id-block"', 'HTML id for test block is valid.');
}
}
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockInvalidRegionTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockInvalidRegionTest.php
index f372c13..da22d5a 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockInvalidRegionTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockInvalidRegionTest.php
@@ -32,7 +32,11 @@ public static function getInfo() {
function setUp() {
parent::setUp();
// Create an admin user.
- $admin_user = $this->drupalCreateUser(array('administer site configuration', 'access administration pages'));
+ $admin_user = $this->drupalCreateUser(array(
+ 'administer site configuration',
+ 'access administration pages',
+ 'administer blocks',
+ ));
$this->drupalLogin($admin_user);
}
@@ -41,20 +45,21 @@ function setUp() {
*/
function testBlockInInvalidRegion() {
// Enable a test block in the default theme and place it in an invalid region.
- db_merge('block')
- ->key(array(
- 'module' => 'block_test',
- 'delta' => 'test_html_id',
- 'theme' => variable_get('theme_default', 'stark'),
- ))
- ->fields(array(
- 'status' => 1,
- 'region' => 'invalid_region',
- 'cache' => DRUPAL_NO_CACHE,
- ))
- ->execute();
+ $current_theme = variable_get('default_theme', 'stark');
+ $machine_name = 'test_html_id';
+ $block = array(
+ 'machine_name' => $machine_name,
+ 'region' => 'footer',
+ );
+ $this->drupalPost("admin/structure/block/manage/test_html_id/$current_theme", $block, t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), 'Block was saved.');
+
+ $machine_name = 'plugin.core.block.' . $current_theme . '.' . $machine_name;
+ $config = config($machine_name);
+ $config->set('region', 'invalid_region');
+ $config->save();
- $warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => t('Test block html id'), '%region' => 'invalid_region'));
+ $warning_message = t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $config->get('id'), '%region' => 'invalid_region'));
// Clearing the cache should disable the test block placed in the invalid region.
$this->drupalPost('admin/config/development/performance', array(), 'Clear all caches');
@@ -65,17 +70,9 @@ function testBlockInInvalidRegion() {
$this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
// Place disabled test block in the invalid region of the default theme.
- db_merge('block')
- ->key(array(
- 'module' => 'block_test',
- 'delta' => 'test_html_id',
- 'theme' => variable_get('theme_default', 'stark'),
- ))
- ->fields(array(
- 'region' => 'invalid_region',
- 'cache' => DRUPAL_NO_CACHE,
- ))
- ->execute();
+ $config = config($machine_name);
+ $config->set('region', 'invalid_region');
+ $config->save();
// Clear the cache to check if the warning message is not triggered.
$this->drupalPost('admin/config/development/performance', array(), 'Clear all caches');
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php
index 6d0c6bc..927d217 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockLanguageTest.php
@@ -14,6 +14,7 @@
*/
class BlockLanguageTest extends WebTestBase {
+ protected $adminUser;
/**
* Modules to enable.
*
@@ -29,15 +30,12 @@ public static function getInfo() {
);
}
- /**
- * Tests the visibility settings for the blocks based on language.
- */
- public function testLanguageBlockVisibility() {
+ function setUp() {
+ parent::setUp();
+
// Create a new user, allow him to manage the blocks and the languages.
- $admin_user = $this->drupalCreateUser(array(
- 'administer languages', 'administer blocks',
- ));
- $this->drupalLogin($admin_user);
+ $this->adminUser = $this->drupalCreateUser(array('administer blocks', 'administer languages'));
+ $this->drupalLogin($this->adminUser);
// Add predefined language.
$edit = array(
@@ -45,156 +43,69 @@ public function testLanguageBlockVisibility() {
);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
$this->assertText('French', 'Language added successfully.');
+ }
+ /**
+ * Tests the visibility settings for the blocks based on language.
+ */
+ public function testLanguageBlockVisibility() {
// Check if the visibility setting is available.
- $this->drupalGet('admin/structure/block/add');
- $this->assertField('langcodes[en]', 'Language visibility field is visible.');
-
- // Create a new block.
- $info_name = $this->randomString(10);
- $body = '';
- for ($i = 0; $i <= 100; $i++) {
- $body .= chr(rand(97, 122));
- }
- $edit = array(
- 'regions[stark]' => 'sidebar_first',
- 'info' => $info_name,
- 'title' => 'test',
- 'body[value]' => $body,
- );
- $this->drupalPost('admin/structure/block/add', $edit, t('Save block'));
+ $default_theme = variable_get('theme_default', 'stark');
+ $this->drupalGet('admin/structure/block/manage/system_powered_by_block' . '/' . $default_theme);
+
+ $this->assertField('visibility[language][langcodes][en]', 'Language visibility field is visible.');
- // Set visibility setting for one language.
+ // Enable a standard block and set the visibility setting for one language.
$edit = array(
- 'langcodes[en]' => TRUE,
+ 'visibility[language][langcodes][en]' => TRUE,
+ 'machine_name' => $this->randomName(8),
+ 'region' => 'sidebar_first',
);
- $this->drupalPost('admin/structure/block/manage/block/1/configure', $edit, t('Save block'));
+ $this->drupalPost('admin/structure/block/manage/system_powered_by_block' . '/' . $default_theme, $edit, t('Save block'));
// Change the default language.
$edit = array(
'site_default' => 'fr',
);
- $this->drupalPost('admin/config/regional/language', $edit, t('Save configuration'));
+ $this->drupalpost('admin/config/regional/language', $edit, t('Save configuration'));
// Reset the static cache of the language list.
drupal_static_reset('language_list');
- // Check that a page has a block
- $this->drupalGet('', array('language' => language_load('en')));
- $this->assertText($body, 'The body of the custom block appears on the page.');
+ // Check that a page has a block.
+ $this->drupalget('', array('language' => language_load('en')));
+ $this->assertText('Powered by Drupal', 'The body of the custom block appears on the page.');
- // Check that a page doesn't has a block for the current language anymore
+ // Check that a page doesn't has a block for the current language anymore.
$this->drupalGet('', array('language' => language_load('fr')));
- $this->assertNoText($body, 'The body of the custom block does not appear on the page.');
+ $this->assertNoText('Powered by Drupal', 'The body of the custom block does not appear on the page.');
}
/**
* Tests if the visibility settings are removed if the language is deleted.
*/
public function testLanguageBlockVisibilityLanguageDelete() {
- // Create a new user, allow him to manage the blocks and the languages.
- $admin_user = $this->drupalCreateUser(array(
- 'administer languages', 'administer blocks',
- ));
- $this->drupalLogin($admin_user);
-
- // Add predefined language.
- $edit = array(
- 'predefined_langcode' => 'fr',
- );
- $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
- $this->assertText('French', 'Language added successfully.');
- // Create a new block.
- $info_name = $this->randomString(10);
- $body = '';
- for ($i = 0; $i <= 100; $i++) {
- $body .= chr(rand(97, 122));
- }
+ $default_theme = variable_get('theme_default', 'stark');
+ // Enable a standard block and set the visibility setting for one language.
$edit = array(
- 'regions[stark]' => 'sidebar_first',
- 'info' => $info_name,
- 'title' => 'test',
- 'body[value]' => $body,
+ 'visibility[language][langcodes][fr]' => TRUE,
+ 'machine_name' => 'language_block_test',
+ 'region' => 'sidebar_first',
);
- $this->drupalPost('admin/structure/block/add', $edit, t('Save block'));
+ $this->drupalPost('admin/structure/block/manage/system_powered_by_block' . '/' . $default_theme, $edit, t('Save block'));
- // Set visibility setting for one language.
- $edit = array(
- 'langcodes[fr]' => TRUE,
- );
- $this->drupalPost('admin/structure/block/manage/block/1/configure', $edit, t('Save block'));
-
- // Check that we have an entry in the database after saving the setting.
- $count = db_query('SELECT COUNT(langcode) FROM {block_language} WHERE module = :module AND delta = :delta', array(
- ':module' => 'block',
- ':delta' => '1'
- ))->fetchField();
- $this->assertTrue($count == 1, 'The block language visibility has an entry in the database.');
+ // Check that we have the language in config fter saving the setting.
+ $config = config('plugin.core.block.' . $default_theme . '.language_block_test');
+ $setting = $config->get('visibility.language.langcodes.fr');
+ $this->assertTrue('fr' === $setting, 'Language was set in the block config.');
// Delete the language.
$this->drupalPost('admin/config/regional/language/delete/fr', array(), t('Delete'));
- // Check that the setting related to this language has been deleted.
- $count = db_query('SELECT COUNT(langcode) FROM {block_language} WHERE module = :module AND delta = :delta', array(
- ':module' => 'block',
- ':delta' => '1'
- ))->fetchField();
- $this->assertTrue($count == 0, 'The block language visibility do not have an entry in the database.');
- }
-
- /**
- * Tests if the visibility settings are removed if the block is deleted.
- */
- public function testLanguageBlockVisibilityBlockDelete() {
- // Create a new user, allow him to manage the blocks and the languages.
- $admin_user = $this->drupalCreateUser(array(
- 'administer languages', 'administer blocks',
- ));
- $this->drupalLogin($admin_user);
-
- // Add predefined language.
- $edit = array(
- 'predefined_langcode' => 'fr',
- );
- $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
- $this->assertText('French', 'Language added successfully.');
-
- // Create a new block.
- $info_name = $this->randomString(10);
- $body = '';
- for ($i = 0; $i <= 100; $i++) {
- $body .= chr(rand(97, 122));
- }
- $edit = array(
- 'regions[stark]' => 'sidebar_first',
- 'info' => $info_name,
- 'title' => 'test',
- 'body[value]' => $body,
- );
- $this->drupalPost('admin/structure/block/add', $edit, t('Save block'));
-
- // Set visibility setting for one language.
- $edit = array(
- 'langcodes[fr]' => TRUE,
- );
- $this->drupalPost('admin/structure/block/manage/block/1/configure', $edit, t('Save block'));
-
- // Check that we have an entry in the database after saving the setting.
- $count = db_query('SELECT COUNT(langcode) FROM {block_language} WHERE module = :module AND delta = :delta', array(
- ':module' => 'block',
- ':delta' => '1'
- ))->fetchField();
- $this->assertTrue($count == 1, 'The block language visibility has an entry in the database.');
-
- // Delete the custom block.
- $this->drupalPost('admin/structure/block/manage/block/1/delete', array(), t('Delete'));
-
- // Check that the setting related to this block has been deleted.
- $count = db_query('SELECT COUNT(langcode) FROM {block_language} WHERE module = :module AND delta = :delta', array(
- ':module' => 'block',
- ':delta' => '1'
- ))->fetchField();
- $this->assertTrue($count == 0, 'The block language visibility do not have an entry in the database.');
+ // Check that we have the language in config fter saving the setting.
+ $config = config('plugin.core.block.' . $default_theme . '.language_block_test');
+ $setting = $config->get('visibility.language.langcodes.fr');
+ $this->assertFalse('fr' === $setting, 'Language was not set in the block config.');
}
}
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php
index 3b5b389..c72236d 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php
@@ -7,13 +7,20 @@
namespace Drupal\block\Tests;
-use Drupal\simpletest\UnitTestBase;
-use stdClass;
+use Drupal\simpletest\WebTestBase;
/**
* Unit tests for template_preprocess_block().
*/
-class BlockTemplateSuggestionsUnitTest extends UnitTestBase {
+class BlockTemplateSuggestionsUnitTest extends WebTestBase {
+
+ /**
+ * Modules to enable.
+ *
+ * @var array
+ */
+ public static $modules = array('block');
+
public static function getInfo() {
return array(
'name' => 'Block template suggestions',
@@ -26,31 +33,23 @@ public static function getInfo() {
* Test if template_preprocess_block() handles the suggestions right.
*/
function testBlockThemeHookSuggestions() {
- // Define block delta with underscore to be preprocessed
- $block1 = new stdClass();
- $block1->module = 'block';
- $block1->delta = 'underscore_test';
- $block1->region = 'footer';
- $variables1 = array();
- $variables1['elements']['#block'] = $block1;
- $variables1['elements']['#children'] = '';
- template_preprocess_block($variables1);
- $this->assertEqual($variables1['theme_hook_suggestions'], array('block__footer', 'block__block', 'block__block__underscore_test'), 'Found expected block suggestions for delta with underscore');
-
- // Define block delta with hyphens to be preprocessed. Hyphens should be
- // replaced with underscores.
- $block2 = new stdClass();
- $block2->module = 'block';
- $block2->delta = 'hyphen-test';
- $block2->region = 'footer';
- $variables2 = array();
- $variables2['elements']['#block'] = $block2;
- $variables2['elements']['#children'] = '';
+ // Define a block with a derivative to be preprocessed, which includes both
+ // an underscore (not transformed) and a hyphen (transformed to underscore),
+ // and generates possibilities for each level of derivative.
+
+ $data = array(
+ 'region' => 'footer',
+ );
+
+ // $block3 = block_load('system_powered_by_block', $data3);
+ $block = drupal_container()->get('plugin.manager.block')->createInstance('system_menu_block:menu-admin', $data);
+ $variables = array();
+ $variables['elements']['#block'] = $block;
+ $variables['elements']['#children'] = '';
// Test adding a class to the block content.
- $variables2['content_attributes']['class'][] = 'test-class';
- template_preprocess_block($variables2);
- $this->assertEqual($variables2['theme_hook_suggestions'], array('block__footer', 'block__block', 'block__block__hyphen_test'), 'Hyphens (-) in block delta were replaced by underscore (_)');
- // Test that the default class and added class are available.
- $this->assertEqual($variables2['content_attributes']['class'], array('test-class', 'content'), 'Default .content class added to block content_attributes_array');
+ $variables['content_attributes']['class'][] = 'test-class';
+ template_preprocess_block($variables);
+ $this->assertEqual($variables['theme_hook_suggestions'], array('block__footer', 'block__system', 'block__system_menu_block', 'block__system_menu_block__menu_admin'));
+ $this->assertEqual($variables['content_attributes']['class'], array('test-class', 'content'), 'Default .content class added to block content_attributes_array');
}
}
diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
index 01d3b67..d1c4233 100644
--- a/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
+++ b/core/modules/block/lib/Drupal/block/Tests/BlockTest.php
@@ -2,7 +2,7 @@
/**
* @file
- * Definition of Drupal\block\Tests\BlockTest.
+ * Contains \Drupal\block\Tests\BlockTest.
*/
namespace Drupal\block\Tests;
@@ -16,15 +16,15 @@ class BlockTest extends WebTestBase {
*
* @var array
*/
- public static $modules = array('block', 'test_page_test');
+ public static $modules = array('block', 'custom_block', 'test_page_test');
protected $regions;
- protected $admin_user;
+ protected $adminUser;
public static function getInfo() {
return array(
'name' => 'Block functionality',
- 'description' => 'Add, edit and delete custom block. Configure and move a module-defined block.',
+ 'description' => 'Custom block functionality.',
'group' => 'Block',
);
}
@@ -46,14 +46,14 @@ function setUp() {
// Create and log in an administrative user having access to the Full HTML
// text format.
- $this->admin_user = $this->drupalCreateUser(array(
+ $this->adminUser = $this->drupalCreateUser(array(
'administer blocks',
filter_permission_name($full_html_format),
'access administration pages',
));
- $this->drupalLogin($this->admin_user);
+ $this->drupalLogin($this->adminUser);
- // Define the existing regions
+ // Define the existing regions.
$this->regions = array();
$this->regions[] = 'header';
$this->regions[] = 'sidebar_first';
@@ -63,19 +63,30 @@ function setUp() {
}
/**
+ * Removes default blocks to avoid conflicts in the Block UI.
+ */
+ protected function removeDefaultBlocks() {
+ $default_theme = variable_get('theme_default', 'stark');
+ $manager = $this->container->get('plugin.manager.block');
+ $instances = config_get_storage_names_with_prefix('plugin.core.block.' . $default_theme);
+ foreach ($instances as $plugin_id) {
+ config($plugin_id)->delete();
+ }
+ }
+
+ /**
* Test creating custom block, moving it to a specific region and then deleting it.
*/
- function testCustomBlock() {
+ public function testCustomBlock() {
+ $default_theme = variable_get('theme_default', 'stark');
+ $this->removeDefaultBlocks();
+
// Enable a second theme.
theme_enable(array('seven'));
// Confirm that the add block link appears on block overview pages.
- $this->drupalGet('admin/structure/block');
- $this->assertLink(t('Add block'));
- $this->assertLinkByHref('admin/structure/block/add');
- $this->drupalGet('admin/structure/block/list/seven');
- $this->assertLink(t('Add block'));
- $this->assertLinkByHref('admin/structure/block/list/seven/add');
+ $this->drupalGet("admin/structure/block/list/block_plugin_ui:$default_theme/add");
+ $this->assertLink(t('Add Custom Block'));
// Confirm that hidden regions are not shown as options for block placement
// when adding a new block.
@@ -92,68 +103,70 @@ function testCustomBlock() {
}
// Add a new custom block by filling out the input form on the admin/structure/block/add page.
- $custom_block = array();
- $custom_block['info'] = $this->randomName(8);
+ $info = strtolower($this->randomName(8));
+ $custom_block['machine_name'] = $info;
+ $custom_block['info'] = $info;
$custom_block['title'] = $this->randomName(8);
$custom_block['body[value]'] = $this->randomName(32);
- $this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
+ $custom_block['region'] = $this->regions[0];
+ $this->drupalPost("admin/structure/block/list/block_plugin_ui:$default_theme/add/custom_blocks", $custom_block, t('Save block'));
+ $plugin_id = "plugin.core.block.$default_theme.$info";
+ $block = $this->container->get('plugin.manager.block')->getInstance(array('config' => $plugin_id));
+ $config = $block->getConfig();
// Confirm that the custom block has been created, and then query the created bid.
- $this->assertText(t('The block has been created.'), 'Custom block successfully created.');
- $bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
-
- // Check to see if the custom block was created by checking that it's in the database.
- $this->assertNotNull($bid, 'Custom block found in database');
+ $this->assertText(t('The block configuration has been saved.'), 'Custom block successfully created.');
// Check that block_block_view() returns the correct title and content.
- $data = block_block_view($bid);
- $format = db_query("SELECT format FROM {block_custom} WHERE bid = :bid", array(':bid' => $bid))->fetchField();
- $this->assertTrue(array_key_exists('subject', $data) && empty($data['subject']), 'block_block_view() provides an empty block subject, since custom blocks do not have default titles.');
- $this->assertEqual(check_markup($custom_block['body[value]'], $format), $data['content'], 'block_block_view() provides correct block content.');
+ $data = $block->build();
+ $format = $config['format'];
+ $this->assertEqual(check_markup($custom_block['body[value]'], $format), render($data), 'BlockInterface::build() provides correct block content.');
// Check whether the block can be moved to all available regions.
$custom_block['module'] = 'block';
- $custom_block['delta'] = $bid;
foreach ($this->regions as $region) {
$this->moveBlockToRegion($custom_block, $region);
}
// Verify presence of configure and delete links for custom block.
$this->drupalGet('admin/structure/block');
- $this->assertLinkByHref('admin/structure/block/manage/block/' . $bid . '/configure', 0, 'Custom block configure link found.');
- $this->assertLinkByHref('admin/structure/block/manage/block/' . $bid . '/delete', 0, 'Custom block delete link found.');
+ $config_block_id = "admin/structure/block/manage/plugin.core.block.$default_theme.$info/$default_theme";
+ $this->assertLinkByHref("$config_block_id/configure", 0, 'Custom block configure link found.');
+ $this->assertLinkByHref("$config_block_id/delete", 0, 'Custom block delete link found.');
// Set visibility only for authenticated users, to verify delete functionality.
$edit = array();
- $edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE;
- $this->drupalPost('admin/structure/block/manage/block/' . $bid . '/configure', $edit, t('Save block'));
+ $edit['visibility[role][roles][' . DRUPAL_AUTHENTICATED_RID . ']'] = TRUE;
+ $this->drupalPost("$config_block_id/configure", $edit, t('Save block'));
// Delete the created custom block & verify that it's been deleted and no longer appearing on the page.
$this->clickLink(t('delete'));
- $this->drupalPost('admin/structure/block/manage/block/' . $bid . '/delete', array(), t('Delete'));
- $this->assertRaw(t('The block %title has been removed.', array('%title' => $custom_block['info'])), 'Custom block successfully deleted.');
+ $this->drupalPost("$config_block_id/delete", array(), t('Delete'));
+ $this->assertRaw(t('The block %title has been removed.', array('%title' => $custom_block['title'])), 'Custom block successfully deleted.');
+ $this->drupalGet(NULL);
$this->assertNoText(t($custom_block['title']), 'Custom block no longer appears on page.');
- $count = db_query("SELECT 1 FROM {block_role} WHERE module = :module AND delta = :delta", array(':module' => $custom_block['module'], ':delta' => $custom_block['delta']))->fetchField();
- $this->assertFalse($count, 'Table block_role being cleaned.');
}
/**
* Test creating custom block using Full HTML.
*/
- function testCustomBlockFormat() {
+ public function testCustomBlockFormat() {
+ $default_theme = variable_get('theme_default', 'stark');
+ $this->removeDefaultBlocks();
+
// Add a new custom block by filling out the input form on the admin/structure/block/add page.
- $custom_block = array();
- $custom_block['info'] = $this->randomName(8);
+ $info = $this->randomName(8);
+ $custom_block['machine_name'] = $info;
+ $custom_block['info'] = $info;
$custom_block['title'] = $this->randomName(8);
$custom_block['body[value]'] = '' . format_plural($authenticated_count, 'There is currently 1 user online.', 'There are currently @count users online.') . '
', + ); + + // Display a list of currently online users. + $max_users = $this->configuration['max_list_count']; + if ($authenticated_count && $max_users) { + $uids = db_query_range('SELECT uid FROM {users} WHERE access >= :interval AND uid > 0 ORDER BY access DESC', 0, $max_users, array(':interval' => $interval))->fetchCol(); + foreach (user_load_multiple($uids) as $account) { + $build['#items'][] = theme('username', array('account' => $account)); + } + } + + return $build; + } + +} diff --git a/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php b/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php index 8b79b69..7190521 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserAccountLinksTests.php @@ -19,7 +19,7 @@ class UserAccountLinksTests extends WebTestBase { * * @var array */ - public static $modules = array('menu'); + public static $modules = array('menu', 'block'); public static function getInfo() { return array( diff --git a/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php b/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php index ed8ad5a..a4458d4 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserBlocksTests.php @@ -21,32 +21,41 @@ class UserBlocksTests extends WebTestBase { */ public static $modules = array('block'); + /** + * The admin user used in this test. + * + * @var \Drupal\user\Plugin\Core\Entity\User + */ + protected $adminUser; + public static function getInfo() { return array( 'name' => 'User blocks', 'description' => 'Test user blocks.', - 'group' => 'User' + 'group' => 'User', ); } function setUp() { parent::setUp(); - // Enable user login block. - db_merge('block') - ->key(array( - 'module' => 'user', - 'delta' => 'login', - 'theme' => variable_get('theme_default', 'stark'), - )) - ->fields(array( - 'status' => 1, - 'weight' => 0, - 'region' => 'sidebar_first', - 'pages' => '', - 'cache' => -1, - )) - ->execute(); + $this->adminUser = $this->drupalCreateUser(array('administer blocks')); + $this->drupalLogin($this->adminUser); + + $block_id = 'user_login_block'; + $default_theme = variable_get('theme_default', 'stark'); + + $block = array( + 'title' => $this->randomName(8), + 'machine_name' => $this->randomName(8), + 'region' => 'sidebar_first', + ); + + // Enable the user login block. + $this->drupalPost('admin/structure/block/manage/' . $block_id . '/' . $default_theme, $block, t('Save block')); + $this->assertText(t('The block configuration has been saved.'), 'User login block enabled'); + $this->plugin_id = 'plugin.core.block.' . $default_theme . '.' . $block['machine_name']; + $this->drupalLogout($this->adminUser); } /** @@ -84,6 +93,10 @@ function testUserLoginBlock() { * Test the Who's Online block. */ function testWhosOnlineBlock() { + $plugin_id = 'plugin.core.block.' . variable_get('theme_default', 'stark') . '.online'; + $block = $this->container->get('plugin.manager.block')->getInstance(array('config' => $plugin_id)); + $config = $block->getConfig(); + // Generate users. $user1 = $this->drupalCreateUser(array()); $user2 = $this->drupalCreateUser(array()); @@ -93,13 +106,15 @@ function testWhosOnlineBlock() { $this->updateAccess($user1->uid); $this->updateAccess($user2->uid, REQUEST_TIME + 1); - // Insert an inactive user who should not be seen in the block. - $this->updateAccess($user3->uid, REQUEST_TIME - config('user.block')->get('seconds_online') - 1); + // Insert an inactive user who should not be seen in the block, and ensure + // that the admin user used in setUp() does not appear. + $inactive_time = REQUEST_TIME - $config['seconds_online'] - 1; + $this->updateAccess($user3->uid, $inactive_time); + $this->updateAccess($this->adminUser->uid, $inactive_time); // Test block output. - $block = user_block_view('online'); - $block['content'] = render($block['content']); - $this->drupalSetContent($block['content']); + $content = $block->build(); + $this->drupalSetContent(render($content)); $this->assertRaw(t('2 users'), 'Correct number of online users (2 users).'); $this->assertText($user1->name, 'Active user 1 found in online list.'); $this->assertText($user2->name, 'Active user 2 found in online list.'); diff --git a/core/modules/user/user.install b/core/modules/user/user.install index bb86002..8d0ed01 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -650,22 +650,9 @@ function user_update_8009(&$sandbox) { } /** - * Moves user_block_* settings from variable to config. - * - * @ingroup config_upgrade - */ -function user_update_8010() { - update_variables_to_config('user.block', array( - 'user_block_max_list_count' => 'max_list_count', - 'user_block_seconds_online' => 'seconds_online', - 'user_block_whois_new_count' => 'whois_new_count', - )); -} - -/** * Create user picture field. */ -function user_update_8011() { +function user_update_8010() { global $user; // User pictures can only be migrated to the new user picture image field @@ -755,7 +742,7 @@ function user_update_8011() { /** * Migrate {users}.picture to 'user_picture' image field. */ -function user_update_8012(&$sandbox) { +function user_update_8011(&$sandbox) { // Initialize total values to process. if (!isset($sandbox['total'])) { $sandbox['total'] = (int) db_query('SELECT COUNT(picture) FROM {users} WHERE picture > 0')->fetchField(); @@ -823,7 +810,7 @@ function user_update_8012(&$sandbox) { /** * Deletes {users}.picture field. */ -function user_update_8013() { +function user_update_8012() { db_drop_field('users', 'picture'); } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 8d73b82..94dc8c8 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -635,193 +635,18 @@ function user_validate_current_pass(&$form, &$form_state) { } /** - * Implements hook_block_info(). - */ -function user_block_info() { - global $user; - - $blocks['login']['info'] = t('User login'); - // Not worth caching. - $blocks['login']['cache'] = DRUPAL_NO_CACHE; - - $blocks['new']['info'] = t('Who\'s new'); - $blocks['new']['properties']['administrative'] = TRUE; - - // Too dynamic to cache. - $blocks['online']['info'] = t('Who\'s online'); - $blocks['online']['cache'] = DRUPAL_NO_CACHE; - $blocks['online']['properties']['administrative'] = TRUE; - - return $blocks; -} - -/** - * Implements hook_block_configure(). - */ -function user_block_configure($delta = '') { - global $user; - - $config = config('user.block'); - - switch ($delta) { - case 'new': - $form['user_block_whois_new_count'] = array( - '#type' => 'select', - '#title' => t('Number of users to display'), - '#default_value' => $config->get('whois_new_count'), - '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), - ); - return $form; - - case 'online': - $period = drupal_map_assoc(array(30, 60, 120, 180, 300, 600, 900, 1800, 2700, 3600, 5400, 7200, 10800, 21600, 43200, 86400), 'format_interval'); - $form['user_block_seconds_online'] = array( - '#type' => 'select', - '#title' => t('User activity'), - '#default_value' => $config->get('seconds_online'), - '#options' => $period, - '#description' => t('A user is considered online for this long after they have last viewed a page.') - ); - $form['user_block_max_list_count'] = array( - '#type' => 'select', - '#title' => t('User list length'), - '#default_value' => $config->get('max_list_count'), - '#options' => drupal_map_assoc(array(0, 5, 10, 15, 20, 25, 30, 40, 50, 75, 100)), - '#description' => t('Maximum number of currently online users to display.') - ); - return $form; - } -} - -/** - * Implements hook_block_save(). - */ -function user_block_save($delta = '', $edit = array()) { - global $user; - $config = config('user.block'); - - switch ($delta) { - case 'new': - $config->set('whois_new_count', $edit['user_block_whois_new_count'])->save(); - break; - - case 'online': - $config->set('seconds_online', $edit['user_block_seconds_online'])->save(); - $config->set('max_list_count', $edit['user_block_max_list_count'])->save(); - break; - } -} - -/** - * Implements hook_block_view(). - */ -function user_block_view($delta = '') { - global $user; - - $block = array(); - $block_config = config('user.block'); - - switch ($delta) { - case 'login': - // For usability's sake, avoid showing two login forms on one page. - if (!$user->uid && !(arg(0) == 'user' && !is_numeric(arg(1)))) { - // Customize the login form. - $form = drupal_get_form('user_login_form'); - unset($form['name']['#attributes']['autofocus']); - unset($form['name']['#description']); - unset($form['pass']['#description']); - $form['name']['#size'] = 15; - $form['pass']['#size'] = 15; - $form['#action'] = url(current_path(), array('query' => drupal_get_destination(), 'external' => FALSE)); - // Build action links. - $items = array(); - if (config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY) { - $items['create_account'] = l(t('Create new account'), 'user/register', array( - 'attributes' => array( - 'title' => t('Create a new user account.'), - 'class' => array('create-account-link'), - ), - )); - } - $items['request_password'] = l(t('Request new password'), 'user/password', array( - 'attributes' => array( - 'title' => t('Request new password via e-mail.'), - 'class' => array('request-password-link'), - ), - )); - // Build a block as renderable array. - $block['subject'] = t('User login'); - $block['content'] = array( - 'user_login_form' => $form, - 'user_links' => array( - '#theme' => 'item_list', - '#items' => $items, - ) - ); - } - return $block; - - case 'new': - if (user_access('access content')) { - // Retrieve a list of new users who have subsequently accessed the site successfully. - $from = 0; - $count = $block_config->get('whois_new_count'); - $items = db_query_range('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', $from, $count)->fetchAll(); - - $block['subject'] = t('Who\'s new'); - $block['content'] = array( - '#theme' => 'item_list__user__new', - '#items' => array(), - ); - foreach ($items as $account) { - $block['content']['#items'][] = theme('username', array('account' => $account)); - } - } - return $block; - - // @todo: Move this block to statistics.module and remove dependency on - // user.access. - case 'online': - if (user_access('access content')) { - // Count users active within the defined period. - $interval = REQUEST_TIME - $block_config->get('seconds_online'); - - // Perform database queries to gather online user lists. - $authenticated_count = db_query("SELECT COUNT(uid) FROM {users} WHERE access >= :timestamp", array(':timestamp' => $interval))->fetchField(); - - $block['subject'] = t('Who\'s online'); - $block['content'] = array( - '#theme' => 'item_list__user__online', - '#items' => array(), - '#prefix' => '' . format_plural($authenticated_count, 'There is currently 1 user online.', 'There are currently @count users online.') . '
', - ); - - // Display a list of currently online users. - $max_users = $block_config->get('max_list_count'); - if ($authenticated_count && $max_users) { - $uids = db_query_range('SELECT uid FROM {users} WHERE access >= :interval AND uid > 0 ORDER BY access DESC', 0, $max_users, array(':interval' => $interval))->fetchCol(); - foreach (user_load_multiple($uids) as $account) { - $block['content']['#items'][] = theme('username', array('account' => $account)); - } - } - } - return $block; - } -} - -/** * Implements hook_preprocess_HOOK() for block.tpl.php. */ function user_preprocess_block(&$variables) { if ($variables['block']->module == 'user') { - switch ($variables['block']->delta) { - case 'login': + switch ($variables['block']->id) { + case 'user_login_block': $variables['attributes']['role'] = 'form'; break; - case 'new': + case 'user_new_block': $variables['attributes']['role'] = 'complementary'; break; - case 'online': + case 'user_online_block': $variables['attributes']['role'] = 'complementary'; break; } diff --git a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php new file mode 100644 index 0000000..45db464 --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsBlock.php @@ -0,0 +1,70 @@ +derivatives) && !empty($this->derivatives[$derivative_id])) { + return $this->derivatives[$derivative_id]; + } + $this->getDerivativeDefinitions($base_plugin_definition); + return $this->derivatives[$derivative_id]; + } + + /** + * Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinitions(). + */ + public function getDerivativeDefinitions(array $base_plugin_definition) { + foreach (views_get_all_views() as $view) { + // disabled views get nothing. + if (!$view->isEnabled()) { + continue; + } + $executable = $view->get('executable'); + $executable->initDisplay(); + foreach ($executable->displayHandlers as $display) { + if (isset($display) && !empty($display->definition['uses_hook_block'])) { + $delta = $view->get('name') . '-' . $display->display['id']; + $desc = $display->getOption('block_description'); + + if (empty($desc)) { + if ($display->display['display_title'] == $display->definition['title']) { + $desc = t('View: !view', array('!view' => $view->getHumanName())); + } + else { + $desc = t('View: !view: !display', array('!view' => $view->getHumanName(), '!display' => $display->display['display_title'])); + } + } + $this->derivatives[$delta] = array( + 'subject' => $desc, + 'cache' => $display->getCacheType() + ); + $this->derivatives[$delta] += $base_plugin_definition; + } + } + } + return $this->derivatives; + } + +} diff --git a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsExposedFilterBlock.php b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsExposedFilterBlock.php new file mode 100644 index 0000000..f0408f9 --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsExposedFilterBlock.php @@ -0,0 +1,63 @@ +derivatives) && !empty($this->derivatives[$derivative_id])) { + return $this->derivatives[$derivative_id]; + } + $this->getDerivativeDefinitions($base_plugin_definition); + return $this->derivatives[$derivative_id]; + } + + /** + * Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinitions(). + */ + public function getDerivativeDefinitions(array $base_plugin_definition) { + foreach (views_get_all_views() as $view) { + // disabled views get nothing. + if (!$view->isEnabled()) { + continue; + } + $executable = $view->get('executable'); + $executable->initDisplay(); + foreach ($executable->displayHandlers as $display) { + if (isset($display) && $display->getOption('exposed_block')) { + if ($display->usesExposedFormInBlock()) { + $delta = $view->get('name') . '-' . $display->display['id']; + $desc = t('Exposed form: @view-@display_id', array('@view' => $view->get('name'), '@display_id' => $display->display['id'])); + $this->derivatives[$delta] = array( + 'subject' => $desc, + 'cache' => DRUPAL_NO_CACHE, + ); + $this->derivatives[$delta] += $base_plugin_definition; + } + } + } + } + return $this->derivatives; + } + +} diff --git a/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php new file mode 100644 index 0000000..c8b6c59 --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsBlock.php @@ -0,0 +1,85 @@ +getPluginId()); + list($name, $this->displayID) = explode('-', $delta, 2); + // Load the view. + $this->view = views_get_view($name); + $this->view->setDisplay($this->displayID); + } + + /** + * Overrides \Drupal\block\BlockBase::configureWrapper(). + */ + public function configureWrapper($form, &$form_state) { + $form = parent::configureWrapper($form, $form_state); + + // Set the default subject to '' so the views internal title is used. + $form['settings']['title']['#default_value'] = ''; + $form['settings']['title']['#access'] = FALSE; + return $form; + } + + /** + * Overrides \Drupal\block\BlockBase::access(). + */ + public function access() { + return $this->view->access($this->displayID); + } + + /** + * Overrides \Drupal\block\BlockBase::build(). + */ + public function build() { + $output = $this->view->executeDisplay($this->displayID); + // Before returning the block output, convert it to a renderable array + // with contextual links. + views_add_block_contextual_links($output, $this->view, $this->displayID); + $this->view->destroy(); + return $output; + } + +} diff --git a/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsExposedFilterBlock.php b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsExposedFilterBlock.php new file mode 100644 index 0000000..d35fe36 --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Plugin/block/block/ViewsExposedFilterBlock.php @@ -0,0 +1,38 @@ +view->display_handler->viewSpecialBlocks($type); + // Before returning the block output, convert it to a renderable + // array with contextual links. + views_add_block_contextual_links($output, $this->view, $this->display_id, 'special_block_' . $type); + $this->view->destroy(); + return $output; + } + +} diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index c272180..2749934 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -2678,7 +2678,7 @@ public function getSpecialBlocks() { * Render any special blocks provided for this display. */ public function viewSpecialBlocks($type) { - if ($type == '-exp') { + if ($type == 'exp') { // avoid interfering with the admin forms. if (arg(0) == 'admin' && arg(1) == 'structure' && arg(2) == 'views') { return; diff --git a/core/modules/views/lib/Drupal/views/Tests/UI/OverrideDisplaysTest.php b/core/modules/views/lib/Drupal/views/Tests/UI/OverrideDisplaysTest.php index 35ff022..193f0fb 100644 --- a/core/modules/views/lib/Drupal/views/Tests/UI/OverrideDisplaysTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/UI/OverrideDisplaysTest.php @@ -44,31 +44,31 @@ function testOverrideDisplays() { $this->drupalPost("admin/structure/views/nojs/display/{$view['name']}/page_1/title", $edit, t('Apply')); $this->drupalPost("admin/structure/views/view/{$view['name']}/edit/page_1", array(), t('Save')); - // Put the block into the first sidebar region, and make sure it will not - // display on the view's page display (since we will be searching for the - // presence/absence of the view's title in both the page and the block). - $this->drupalGet('admin/structure/block'); - $edit = array(); - $edit["blocks[views_{$view['name']}-block_1][region]"] = 'sidebar_first'; - $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); - $edit = array(); - $edit['visibility'] = BLOCK_VISIBILITY_NOTLISTED; - $edit['pages'] = $view_path; - $this->drupalPost("admin/structure/block/manage/views/{$view['name']}-block_1/configure", $edit, t('Save block')); - // Add a node that will appear in the view, so that the block will actually // be displayed. $this->drupalCreateNode(); - // Make sure the title appears in both the page and the block. + // Make sure the title appears in the page. $this->drupalGet($view_path); $this->assertResponse(200); $this->assertText($original_title); + + // Put the block into the first sidebar region. + $default_theme = variable_get('theme_default', 'stark'); + $this->drupalGet("admin/structure/block/list/block_plugin_ui:{$default_theme}/add"); + $this->assertText('View: ' . $view['human_name']); + $block = array( + 'machine_name' => $this->randomName(8), + 'region' => 'sidebar_first', + ); + $this->drupalPost("admin/structure/block/manage/views_block:{$view['name']}-block_1/{$default_theme}", $block, t('Save block')); + + // Make sure the title appears in the block. $this->drupalGet(''); $this->assertText($original_title); - // Change the title for the page display only, and make sure that is the - // only one that is changed. + // Change the title for the page display only, and make sure that the original title + // still appears on the page. $edit = array(); $edit['title'] = $new_title = $this->randomName(16); $edit['override[dropdown]'] = 'page_1'; @@ -77,10 +77,7 @@ function testOverrideDisplays() { $this->drupalGet($view_path); $this->assertResponse(200); $this->assertText($new_title); - $this->assertNoText($original_title); - $this->drupalGet(''); $this->assertText($original_title); - $this->assertNoText($new_title); } /** @@ -102,17 +99,6 @@ function testWizardMixedDefaultOverriddenDisplays() { $view['block[title]'] = $this->randomName(16); $this->drupalPost('admin/structure/views/add', $view, t('Save & exit')); - // Put the block into the first sidebar region, and make sure it will not - // display on the view's page display (since we will be searching for the - // presence/absence of the view's title in both the page and the block). - $this->drupalGet('admin/structure/block'); - $edit = array(); - $edit["blocks[views_{$view['name']}-block_1][region]"] = 'sidebar_first'; - $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); - $edit = array(); - $edit['visibility'] = BLOCK_VISIBILITY_NOTLISTED; - $edit['pages'] = $view['page[path]']; - $this->drupalPost("admin/structure/block/manage/views/{$view['name']}-block_1/configure", $edit, t('Save block')); // Add a node that will appear in the view, so that the block will actually // be displayed. @@ -128,6 +114,16 @@ function testWizardMixedDefaultOverriddenDisplays() { $this->assertResponse(200); $this->assertText($view['page[title]']); $this->assertNoText($view['block[title]']); + + // Put the block into the first sidebar region. + $default_theme = variable_get('theme_default', 'stark'); + $this->drupalGet("admin/structure/block/list/block_plugin_ui:{$default_theme}/add"); + $this->assertText('View: ' . $view['human_name']); + $block = array( + 'machine_name' => $this->randomName(8), + 'region' => 'sidebar_first', + ); + $this->drupalPost("admin/structure/block/manage/views_block:{$view['name']}-block_1/{$default_theme}", $block, t('Save block')); $this->drupalGet(''); $this->assertText($view['block[title]']); $this->assertNoText($view['page[title]']); @@ -142,7 +138,6 @@ function testWizardMixedDefaultOverriddenDisplays() { $this->assertResponse(200); $this->assertText($new_default_title); $this->assertNoText($view['page[title]']); - $this->assertNoText($view['block[title]']); $this->drupalGet($view['page[feed_properties][path]']); $this->assertResponse(200); $this->assertText($new_default_title); @@ -162,7 +157,6 @@ function testWizardMixedDefaultOverriddenDisplays() { $this->drupalGet($view['page[path]']); $this->assertResponse(200); $this->assertText($new_default_title); - $this->assertNoText($new_block_title); $this->drupalGet($view['page[feed_properties][path]']); $this->assertResponse(200); $this->assertText($new_default_title); diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/BasicTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/BasicTest.php index dbf48ff..1f8a318 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/BasicTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/BasicTest.php @@ -121,11 +121,14 @@ function testViewsWizardAndListing() { $this->assertLinkByHref(url($view3['page[path]'])); // Put the block into the first sidebar region. - $this->drupalGet('admin/structure/block'); + $default_theme = variable_get('theme_default', 'stark'); + $this->drupalGet("admin/structure/block/list/block_plugin_ui:{$default_theme}/add"); $this->assertText('View: ' . $view3['human_name']); - $edit = array(); - $edit["blocks[views_{$view3['name']}-block_1][region]"] = 'sidebar_first'; - $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); + $block = array( + 'machine_name' => $this->randomName(8), + 'region' => 'sidebar_first', + ); + $this->drupalPost("admin/structure/block/manage/views_block:{$view3['name']}-block_1/{$default_theme}", $block, t('Save block')); // Visit a random page (not the one that displays the view itself) and look // for the expected node title in the block. diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/ItemsPerPageTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/ItemsPerPageTest.php index 3e69105..525cd7d 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/ItemsPerPageTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/ItemsPerPageTest.php @@ -73,14 +73,18 @@ function testItemsPerPage() { $pos2 = strpos($content, $node2->label()); $this->assertTrue($pos5 < $pos4 && $pos4 < $pos3 && $pos3 < $pos2, t('The nodes appear in the expected order in the page display.')); + $default_theme = variable_get('theme_default', 'stark'); + $this->drupalGet("admin/structure/block/list/block_plugin_ui:{$default_theme}/add"); + $this->assertText('View: ' . $view['human_name']); // Put the block into the first sidebar region, visit a page that displays // the block, and check that the nodes we expect appear in the correct // order. - $this->drupalGet('admin/structure/block'); - $this->assertText('View: ' . $view['human_name']); - $edit = array(); - $edit["blocks[views_{$view['name']}-block_1][region]"] = 'sidebar_first'; - $this->drupalPost('admin/structure/block', $edit, t('Save blocks')); + $block = array( + 'machine_name' => $this->randomName(8), + 'region' => 'sidebar_first', + ); + $this->drupalPost("admin/structure/block/manage/views_block:{$view['name']}-block_1/{$default_theme}", $block, t('Save block')); + $this->drupalGet('user'); $content = $this->drupalGetContent(); $this->assertText($node5->label()); diff --git a/core/profiles/minimal/minimal.install b/core/profiles/minimal/minimal.install index 4e42e6d..0c3aafb 100644 --- a/core/profiles/minimal/minimal.install +++ b/core/profiles/minimal/minimal.install @@ -14,45 +14,6 @@ function minimal_install() { $default_theme = 'stark'; - // Enable some standard blocks. - $values = array( - array( - 'module' => 'user', - 'delta' => 'login', - 'theme' => $default_theme, - 'status' => 1, - 'weight' => 0, - 'region' => 'sidebar_first', - 'pages' => '', - 'cache' => -1, - ), - array( - 'module' => 'system', - 'delta' => 'menu-tools', - 'theme' => $default_theme, - 'status' => 1, - 'weight' => 0, - 'region' => 'sidebar_first', - 'pages' => '', - 'cache' => -1, - ), - array( - 'module' => 'system', - 'delta' => 'menu-admin', - 'theme' => $default_theme, - 'status' => 1, - 'weight' => 1, - 'region' => 'sidebar_first', - 'pages' => '', - 'cache' => -1, - ), - ); - $query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache')); - foreach ($values as $record) { - $query->values($record); - } - $query->execute(); - // Set front page to "node". config('system.site')->set('page.front', 'node')->save(); diff --git a/core/profiles/standard/config/plugin.core.block.bartik.content.yml b/core/profiles/standard/config/plugin.core.block.bartik.content.yml new file mode 100644 index 0000000..e10f903 --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.bartik.content.yml @@ -0,0 +1,18 @@ +id: system_main_block +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: system +region: content +weight: '0' diff --git a/core/profiles/standard/config/plugin.core.block.bartik.footer.yml b/core/profiles/standard/config/plugin.core.block.bartik.footer.yml new file mode 100644 index 0000000..d1c0c36 --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.bartik.footer.yml @@ -0,0 +1,18 @@ +id: 'system_menu_block:menu-footer' +status: '1' +cache: '-1' +subject: 'System Menu: Footer menu' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +module: system +region: footer +weight: '0' diff --git a/core/profiles/standard/config/plugin.core.block.bartik.help.yml b/core/profiles/standard/config/plugin.core.block.bartik.help.yml new file mode 100644 index 0000000..a5c4467 --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.bartik.help.yml @@ -0,0 +1,18 @@ +id: system_help_block +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: system +region: help +weight: '0' diff --git a/core/profiles/standard/config/plugin.core.block.bartik.login.yml b/core/profiles/standard/config/plugin.core.block.bartik.login.yml new file mode 100644 index 0000000..6eeeb34 --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.bartik.login.yml @@ -0,0 +1,19 @@ +id: user_login_block +whois_new_count: '5' +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: user +region: sidebar_first +weight: '0' diff --git a/core/profiles/standard/config/plugin.core.block.bartik.navigation.yml b/core/profiles/standard/config/plugin.core.block.bartik.navigation.yml new file mode 100644 index 0000000..a20b790 --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.bartik.navigation.yml @@ -0,0 +1,18 @@ +id: 'system_menu_block:menu-main' +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: system +region: sidebar_first +weight: '0' diff --git a/core/profiles/standard/config/plugin.core.block.bartik.powered.yml b/core/profiles/standard/config/plugin.core.block.bartik.powered.yml new file mode 100644 index 0000000..3ef20d7 --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.bartik.powered.yml @@ -0,0 +1,18 @@ +id: system_powered_by_block +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: system +region: footer +weight: '0' diff --git a/core/profiles/standard/config/plugin.core.block.bartik.search.yml b/core/profiles/standard/config/plugin.core.block.bartik.search.yml new file mode 100644 index 0000000..52a5788 --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.bartik.search.yml @@ -0,0 +1,18 @@ +id: search_form_block +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: search +region: sidebar_first +weight: '0' diff --git a/core/profiles/standard/config/plugin.core.block.bartik.tools.yml b/core/profiles/standard/config/plugin.core.block.bartik.tools.yml new file mode 100644 index 0000000..5e8b188 --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.bartik.tools.yml @@ -0,0 +1,18 @@ +id: 'system_menu_block:menu-tools' +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: system +region: sidebar_first +weight: '0' diff --git a/core/profiles/standard/config/plugin.core.block.seven.content.yml b/core/profiles/standard/config/plugin.core.block.seven.content.yml new file mode 100644 index 0000000..51b155f --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.seven.content.yml @@ -0,0 +1,18 @@ +id: system_main_block +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: system +region: content +weight: '-3' diff --git a/core/profiles/standard/config/plugin.core.block.seven.help.yml b/core/profiles/standard/config/plugin.core.block.seven.help.yml new file mode 100644 index 0000000..a5c4467 --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.seven.help.yml @@ -0,0 +1,18 @@ +id: system_help_block +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: system +region: help +weight: '0' diff --git a/core/profiles/standard/config/plugin.core.block.seven.login.yml b/core/profiles/standard/config/plugin.core.block.seven.login.yml new file mode 100644 index 0000000..dbbcfac --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.seven.login.yml @@ -0,0 +1,19 @@ +region: '-1' +id: user_login_block +whois_new_count: '5' +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: user +weight: '-3' diff --git a/core/profiles/standard/config/plugin.core.block.seven.navigation.yml b/core/profiles/standard/config/plugin.core.block.seven.navigation.yml new file mode 100644 index 0000000..879191e --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.seven.navigation.yml @@ -0,0 +1,18 @@ +region: '-1' +id: 'system_menu_block:menu-main' +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: system +weight: '-2' diff --git a/core/profiles/standard/config/plugin.core.block.seven.powered.yml b/core/profiles/standard/config/plugin.core.block.seven.powered.yml new file mode 100644 index 0000000..b9aac19 --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.seven.powered.yml @@ -0,0 +1,18 @@ +region: '-1' +id: system_powered_by_block +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: system +weight: '0' diff --git a/core/profiles/standard/config/plugin.core.block.seven.search.yml b/core/profiles/standard/config/plugin.core.block.seven.search.yml new file mode 100644 index 0000000..e3cf4c3 --- /dev/null +++ b/core/profiles/standard/config/plugin.core.block.seven.search.yml @@ -0,0 +1,18 @@ +region: '-1' +id: search_form_block +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: search +weight: '-1' diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index 071bf31..784b5fd 100644 --- a/core/profiles/standard/standard.install +++ b/core/profiles/standard/standard.install @@ -76,114 +76,114 @@ function standard_install() { theme_disable(array('stark')); // Enable some standard blocks. - $admin_theme = 'seven'; - $blocks = array( - array( - 'module' => 'system', - 'delta' => 'main', - 'theme' => $default_theme, - 'status' => 1, - 'weight' => 0, - 'region' => 'content', - 'pages' => '', - 'cache' => -1, - ), - array( - 'module' => 'search', - 'delta' => 'form', - 'theme' => $default_theme, - 'status' => 1, - 'weight' => -1, - 'region' => 'sidebar_first', - 'pages' => '', - 'cache' => -1, - ), - array( - 'module' => 'user', - 'delta' => 'login', - 'theme' => $default_theme, - 'status' => 1, - 'weight' => 0, - 'region' => 'sidebar_first', - 'pages' => '', - 'cache' => -1, - ), - array( - 'module' => 'system', - 'delta' => 'menu-tools', - 'theme' => $default_theme, - 'status' => 1, - 'weight' => 0, - 'region' => 'sidebar_first', - 'pages' => '', - 'cache' => -1, - ), - array( - 'module' => 'system', - 'delta' => 'menu-footer', - 'theme' => $default_theme, - 'status' => 1, - 'weight' => 0, - 'region' => 'footer', - 'pages' => '', - 'cache' => -1, - ), - array( - 'module' => 'system', - 'delta' => 'powered-by', - 'theme' => $default_theme, - 'status' => 1, - 'weight' => 10, - 'region' => 'footer', - 'pages' => '', - 'cache' => -1, - ), - array( - 'module' => 'system', - 'delta' => 'help', - 'theme' => $default_theme, - 'status' => 1, - 'weight' => 0, - 'region' => 'help', - 'pages' => '', - 'cache' => -1, - ), - array( - 'module' => 'system', - 'delta' => 'main', - 'theme' => $admin_theme, - 'status' => 1, - 'weight' => 0, - 'region' => 'content', - 'pages' => '', - 'cache' => -1, - ), - array( - 'module' => 'system', - 'delta' => 'help', - 'theme' => $admin_theme, - 'status' => 1, - 'weight' => 0, - 'region' => 'help', - 'pages' => '', - 'cache' => -1, - ), - array( - 'module' => 'user', - 'delta' => 'login', - 'theme' => $admin_theme, - 'status' => 1, - 'weight' => 10, - 'region' => 'content', - 'pages' => '', - 'cache' => -1, - ), - ); - $query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache')); - foreach ($blocks as $block) { - $query->values($block); - } - $query->execute(); + //$admin_theme = 'seven'; + //$blocks = array( + //array( + //'module' => 'system', + //'delta' => 'main', + //'theme' => $default_theme, + //'status' => 1, + //'weight' => 0, + //'region' => 'content', + //'pages' => '', + //'cache' => -1, + //), + //array( + //'module' => 'search', + //'delta' => 'form', + //'theme' => $default_theme, + //'status' => 1, + //'weight' => -1, + //'region' => 'sidebar_first', + //'pages' => '', + //'cache' => -1, + //), + //array( + //'module' => 'user', + //'delta' => 'login', + //'theme' => $default_theme, + //'status' => 1, + //'weight' => 0, + //'region' => 'sidebar_first', + //'pages' => '', + //'cache' => -1, + //), + //array( + //'module' => 'system', + //'delta' => 'menu-tools', + //'theme' => $default_theme, + //'status' => 1, + //'weight' => 0, + //'region' => 'sidebar_first', + //'pages' => '', + //'cache' => -1, + //), + //array( + //'module' => 'system', + //'delta' => 'menu-footer', + //'theme' => $default_theme, + //'status' => 1, + //'weight' => 0, + //'region' => 'footer', + //'pages' => '', + //'cache' => -1, + //), + //array( + //'module' => 'system', + //'delta' => 'powered-by', + //'theme' => $default_theme, + //'status' => 1, + //'weight' => 10, + //'region' => 'footer', + //'pages' => '', + //'cache' => -1, + //), + //array( + //'module' => 'system', + //'delta' => 'help', + //'theme' => $default_theme, + //'status' => 1, + //'weight' => 0, + //'region' => 'help', + //'pages' => '', + //'cache' => -1, + //), + //array( + //'module' => 'system', + //'delta' => 'main', + //'theme' => $admin_theme, + //'status' => 1, + //'weight' => 0, + //'region' => 'content', + //'pages' => '', + //'cache' => -1, + //), + //array( + //'module' => 'system', + //'delta' => 'help', + //'theme' => $admin_theme, + //'status' => 1, + //'weight' => 0, + //'region' => 'help', + //'pages' => '', + //'cache' => -1, + //), + //array( + //'module' => 'user', + //'delta' => 'login', + //'theme' => $admin_theme, + //'status' => 1, + //'weight' => 10, + //'region' => 'content', + //'pages' => '', + //'cache' => -1, + //), + //); + //$query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache')); + //foreach ($blocks as $block) { + //$query->values($block); + //} + //$query->execute(); // Set front page to "node". config('system.site')->set('page.front', 'node')->save(); diff --git a/core/profiles/testing/config/plugin.core.block.stark.admin.yml b/core/profiles/testing/config/plugin.core.block.stark.admin.yml new file mode 100644 index 0000000..960e2cb --- /dev/null +++ b/core/profiles/testing/config/plugin.core.block.stark.admin.yml @@ -0,0 +1,18 @@ +id: 'system_menu_block:menu-admin' +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: system +region: sidebar_first +weight: '0' diff --git a/core/profiles/testing/config/plugin.core.block.stark.online.yml b/core/profiles/testing/config/plugin.core.block.stark.online.yml new file mode 100644 index 0000000..3b3f5c5 --- /dev/null +++ b/core/profiles/testing/config/plugin.core.block.stark.online.yml @@ -0,0 +1,23 @@ +id: user_online_block +properties: + administrative: '1' +seconds_online: '900' +max_list_count: '10' +status: '1' +cache: '-1' +subject: 'Who''s online' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + poll: '0' + visibility__active_tab: edit-visibility-path +module: user +region: sidebar_first +weight: '0' diff --git a/core/profiles/testing/config/plugin.core.block.stark.tools.yml b/core/profiles/testing/config/plugin.core.block.stark.tools.yml new file mode 100644 index 0000000..5e8b188 --- /dev/null +++ b/core/profiles/testing/config/plugin.core.block.stark.tools.yml @@ -0,0 +1,18 @@ +id: 'system_menu_block:menu-tools' +status: '1' +cache: '-1' +visibility: + path: + visibility: '0' + pages: '' + role: + roles: { } + node_type: + types: + article: '0' + page: '0' + visibility__active_tab: edit-visibility-path +subject: '' +module: system +region: sidebar_first +weight: '0'