diff --git a/core/modules/block/block.admin.inc b/core/modules/block/block.admin.inc index f94ce257d1b3bd3cb0ba4f61949d519ed37f81ce..6af9fe398314467984da283e5907ecfa9f8ad42b 100644 --- a/core/modules/block/block.admin.inc +++ b/core/modules/block/block.admin.inc @@ -6,6 +6,7 @@ */ use Drupal\block\Plugin\Core\Entity\Block; +use Drupal\Core\Template\Attribute; /** * Page callback: Attaches CSS for the block region demo. @@ -84,13 +85,13 @@ function block_admin_edit(Block $entity) { } /** - * Processes variables for block-admin-display-form.tpl.php. + * Prepares variables for block admin display form templates. * - * The $variables array contains the following arguments: - * - $form + * Default template: block-admin-display-form.html.twig. * - * @see block-admin-display.tpl.php - * @see theme_block_admin_display() + * @param array $variables + * An associative array containing: + * - form: A render element representing the form. */ function template_preprocess_block_admin_display_form(&$variables) { $variables['block_regions'] = $variables['form']['block_regions']['#value']; @@ -103,6 +104,9 @@ function template_preprocess_block_admin_display_form(&$variables) { $variables['block_listing'][$key] = array(); } + $default_attributes = new Attribute(array('class' => array('draggable'))); + $row = 0; + // Initialize disabled blocks array. $variables['block_listing'][BLOCK_REGION_NONE] = array(); @@ -118,14 +122,28 @@ function template_preprocess_block_admin_display_form(&$variables) { $block['weight']['#attributes']['class'] = array('block-weight', 'block-weight-' . $region); $variables['block_listing'][$region][$i] = new stdClass(); + $variables['block_listing'][$region][$i]->attributes = clone $default_attributes; + $variables['block_listing'][$region][$i]->attributes['class'][] = $row % 2 == 0 ? 'odd' : 'even'; + $row++; + if(!empty($block['#attributes']['class'])) { + $variables['block_listing'][$region][$i]->attributes['class'][] = implode(' ', $block['#attributes']['class']); + } + $variables['block_listing'][$region][$i]->row_class = !empty($block['#attributes']['class']) ? implode(' ', $block['#attributes']['class']) : ''; $variables['block_listing'][$region][$i]->block_modified = !empty($block['#attributes']['class']) && in_array('block-modified', $block['#attributes']['class']); - $variables['block_listing'][$region][$i]->block_title = drupal_render($block['info']); - $variables['block_listing'][$region][$i]->region_select = drupal_render($block['region']) . drupal_render($block['theme']); - $variables['block_listing'][$region][$i]->weight_select = drupal_render($block['weight']); - $variables['block_listing'][$region][$i]->operations = drupal_render($block['operations']); + $variables['block_listing'][$region][$i]->block_title = $block['info']; + $variables['block_listing'][$region][$i]->region_select = array( + 'region' => array( + 'data' => $block['region'], + '#weight' => 1, + ), + 'theme' => array( + 'data' => $block['theme'], + '#weight' => 2, + ), + ); + $variables['block_listing'][$region][$i]->weight_select = $block['weight']; + $variables['block_listing'][$region][$i]->operations = $block['operations']; $variables['block_listing'][$region][$i]->printed = FALSE; } - - $variables['form_submit'] = drupal_render_children($variables['form']); } diff --git a/core/modules/block/block.api.php b/core/modules/block/block.api.php index c2bf7ffd9e12ee362661cb60cb72df4a39f13dea..93a113a7743eca503aab82ba9b33d315c9dd4cf8 100644 --- a/core/modules/block/block.api.php +++ b/core/modules/block/block.api.php @@ -20,7 +20,7 @@ * If the module wishes to act on the rendered HTML of the block rather than * the structured content array, it may use this hook to add a #post_render * callback. Alternatively, it could also implement hook_preprocess_HOOK() for - * block.tpl.php. See drupal_render() and theme() documentation respectively + * block.html.twig. See drupal_render() and theme() documentation respectively * for details. * * In addition to hook_block_view_alter(), which is called for all blocks, there diff --git a/core/modules/block/block.module b/core/modules/block/block.module index d94ec3b3723c9d5db8d25271113a3399cf7d01ae..8b24c9d91d6e136736ecc21cdd50598b8f8c769f 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -515,21 +515,23 @@ function block_rebuild() { } /** - * Processes variables for block.tpl.php. + * Prepares variables for block templates. + * + * Default template: block.html.twig. * * Prepares the values passed to the theme_block function to be passed * into a pluggable template engine. Uses block properties to generate a * series of template file suggestions. If none are found, the default - * block.tpl.php is used. - * - * Most themes utilize their own copy of block.tpl.php. The default is located - * inside "modules/block/block.tpl.php". Look in there for the full list of - * variables. + * block.html.twig is used. * - * The $variables array contains the following arguments: - * - $block + * Most themes use their own copy of block.html.twig. The default is located + * inside "core/modules/block/templates/block.html.twig". Look in there for the + * full list of available variables. * - * @see block.tpl.php + * @param array $variables + * An associative array containing: + * - elements: An associative array containing the properties of the element. + * Properties used: #block, #configuration, #children, #plugin_id. */ function template_preprocess_block(&$variables) { $block_counter = &drupal_static(__FUNCTION__, array()); @@ -566,7 +568,7 @@ function template_preprocess_block(&$variables) { if ($id = $variables['elements']['#block']->id()) { $config_id = explode('.', $id); $machine_name = array_pop($config_id); - $variables['block_html_id'] = drupal_html_id('block-' . $machine_name); + $variables['attributes']['id'] = drupal_html_id('block-' . $machine_name); $variables['theme_hook_suggestions'][] = 'block__' . $machine_name; } } diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php index dfc3b61bd21a20c616c8b06b78b6355f4d6da202..c3fbca30886057ecc615843435eca4755b3b761d 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php @@ -135,11 +135,13 @@ protected function renderTests() { $entity = entity_load('block', 'stark.test_block'); $output = entity_view($entity, 'block'); $expected = array(); - $expected[] = '
'; - $expected[] = ''; + $expected[] = '
'; + $expected[] = ' '; $expected[] = ' '; + $expected[] = ''; $expected[] = '
'; - $expected[] = '
'; + $expected[] = ' '; + $expected[] = '
'; $expected[] = '
'; $expected[] = ''; $expected_output = implode("\n", $expected); @@ -159,12 +161,14 @@ protected function renderTests() { $entity->save(); $output = entity_view($entity, 'block'); $expected = array(); - $expected[] = '
'; - $expected[] = ''; - $expected[] = '

Powered by Bananas

'; + $expected[] = '
'; $expected[] = ' '; + $expected[] = '

Powered by Bananas

'; + $expected[] = ' '; + $expected[] = ''; $expected[] = '
'; - $expected[] = '
'; + $expected[] = ' '; + $expected[] = '
'; $expected[] = '
'; $expected[] = ''; $expected_output = implode("\n", $expected); diff --git a/core/modules/block/templates/block-admin-display-form.html.twig b/core/modules/block/templates/block-admin-display-form.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..545a06cca447a0249cf6345a016c8654a9b401f2 --- /dev/null +++ b/core/modules/block/templates/block-admin-display-form.html.twig @@ -0,0 +1,56 @@ +{# +/** + * @file + * Default theme implementation to configure blocks. + * + * Available variables: + * - block_regions: A collection of regions. Keyed by name with the title as value. + * - block_listing: A collection of blocks keyed by region and then delta. + * - form: The form elements. + * + * Each block_listing[region] contains a collection of blocks for that region. + * - data: Each data in block_listing[region] contains. + * - region_title: Region title for the listed block. + * - block_title: Block title. + * - region_select: Drop-down menu for assigning a region. + * - weight_select: Drop-down menu for setting weights. + * - operations: Block operations. + * + * @see template_preprocess() + * @see template_preprocess_block_admin_display_form() + * + * @ingroup themeable + */ +#} + + + + + + + + + + + {% set row = 0 %} + {% for region, title in block_regions %} + + + + + + + {% for delta, data in block_listing[region] %} + + + + + + + {% set row = row + 1 %} + {% endfor %} + {% endfor %} + +
{{ 'Block'|t }}{{ 'Region'|t }}{{ 'Weight'|t }}{{ 'Operations'|t }}
{{ title }}
{{ 'No blocks in this region'|t }}
{{ data.block_title }}{{ data.region_select }}{{ data.weight_select }}{{ data.operations }}
+ +{{ form }} diff --git a/core/modules/block/templates/block-admin-display-form.tpl.php b/core/modules/block/templates/block-admin-display-form.tpl.php deleted file mode 100644 index 4fa3e703004f5000578c9d92b26f34d6e0d2f581..0000000000000000000000000000000000000000 --- a/core/modules/block/templates/block-admin-display-form.tpl.php +++ /dev/null @@ -1,58 +0,0 @@ -region_title: Region title for the listed block. - * - $data->block_title: Block title. - * - $data->region_select: Drop-down menu for assigning a region. - * - $data->weight_select: Drop-down menu for setting weights. - * - $data->operations: Block operations. - * - * @see template_preprocess_block_admin_display_form() - * @see theme_block_admin_display() - * - * @ingroup themeable - */ -?> - - - - - - - - - - - - $title): ?> - - - - - - - $data): ?> - - - - - - - - - - -
block_title; ?>region_select; ?>weight_select; ?>operations; ?>
- - diff --git a/core/modules/block/templates/block.html.twig b/core/modules/block/templates/block.html.twig new file mode 100644 index 0000000000000000000000000000000000000000..757f8f5053b44b08e174c4df13f300c36772c7d0 --- /dev/null +++ b/core/modules/block/templates/block.html.twig @@ -0,0 +1,55 @@ +{# +/** + * @file + * Default theme implementation to display a block. + * + * Available variables: + * - plugin_id: The ID of the block implementation. + * - label: The configured label of the block if visible. + * - configuration: A list of the block's configuration values. + * - label: The configured label for the block. + * - label_display: The display settings for the label. + * - module: The module that provided this block plugin. + * - cache: The cache settings. + * - Block plugin specific settings will also be stored here. + * - block - The full block entity. + * - label_hidden: The hidden block title value if the block was + * configured to hide the title ('label' is empty in this case). + * - module: The module that generated the block. + * - delta: An ID for the block, unique within each module. + * - region: The block region embedding the current block. + * - content: The content of this block. + * - attributes: HTML attributes for the containing element. + * - id: A valid HTML ID and guaranteed unique. + * - class: Classes that can be used to style contextually through + * CSS. These can be manipulated through preprocess functions. The default + * values can be one or more of the following: + * - block: The current template type, i.e., "theming hook". + * - block-[module]: The module generating the block. For example, the user + * module is responsible for handling the default user navigation block. + * In that case the class would be 'block-user'. + * - title_attributes: HTML attributes for the title element. + * - content_attributes: HTML attributes for the content element. + * - title_prefix: Additional output populated by modules, intended to be + * displayed in front of the main title tag that appears in the template. + * - title_suffix: Additional output populated by modules, intended to be + * displayed after the main title tag that appears in the template. + * + * @see template_preprocess() + * @see template_preprocess_block() + * + * @ingroup themeable + */ + @todo Remove the div around content as per http://drupal.org/node/1972122. +#} + + {{ title_prefix }} + {% if label %} + {{ label }} + {% endif %} + {{ title_suffix }} + + + {{ content }} + + diff --git a/core/modules/block/templates/block.tpl.php b/core/modules/block/templates/block.tpl.php deleted file mode 100644 index 106dd6b3566becebddbe85a1aaacb259824e1c20..0000000000000000000000000000000000000000 --- a/core/modules/block/templates/block.tpl.php +++ /dev/null @@ -1,59 +0,0 @@ - - -
> - -
> - - - - - > - - - - > - -
-
diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 4ae3740a2dec6e553eb346a2a7a7ca279b0e7b1b..59f1e45c7d594f03d0c0a77be624dcfe148b58b8 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -948,7 +948,7 @@ function _book_link_defaults($nid) { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function book_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'book') { diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 807b672c7fa59d80f26f56536052d3adc2215e96..b2d0190914f9b8508d8e7b5d55ee5a44c1ba4b14 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1526,7 +1526,7 @@ function comment_preview(Comment $comment) { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function comment_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'comment') { diff --git a/core/modules/edit/edit.module b/core/modules/edit/edit.module index 7e1d1fe0c11e23df1b15600edadca91f1f4976ac..5b115607aa704de29b3967e7699520d097ffe3a5 100644 --- a/core/modules/edit/edit.module +++ b/core/modules/edit/edit.module @@ -157,7 +157,7 @@ function edit_preprocess_taxonomy_term(&$variables) { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. * * @todo Remove this, handle in generic way: http://drupal.org/node/1972514. */ diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index dfe04f219deb5358972b5674531fb632714aa116..1a5e0091ecc625634416a1756fd336ae856cd5a3 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -973,7 +973,7 @@ function forum_get_topics($tid, $sortby, $forum_per_page) { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function forum_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'forum') { diff --git a/core/modules/help/help.module b/core/modules/help/help.module index d7042d320075f62f1142f9f89a8b8a6461c78daa..4c347f95c5dc2ff70ed1d2455a8ee4eb5c12f716 100644 --- a/core/modules/help/help.module +++ b/core/modules/help/help.module @@ -66,7 +66,7 @@ function help_help($path, $arg) { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function help_preprocess_block(&$variables) { if ($variables['plugin_id'] == 'system_help_block') { diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 6294f3143fcbf748f6df38812fa63421c4082105..1dd936fc8df9e23a691d3e25a608063866e30792 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -760,7 +760,7 @@ function language_language_delete($language) { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function language_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'language') { diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php index 8088f6a64d972b40b7c0029ee6a0e858adbb5722..47a61e73238a2a1893b5603c47ccbc450c6dd4d1 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php @@ -59,7 +59,7 @@ function testLanguageBlock() { $this->assertText($block->label(), 'Language switcher block found.'); // Assert that only the current language is marked as active. - list($language_switcher) = $this->xpath('//div[@id=:id]/div[@class="content"]', array(':id' => 'block-test-language-block')); + list($language_switcher) = $this->xpath('//div[@id=:id]/div[contains(@class, "content")]', array(':id' => 'block-test-language-block')); $links = array( 'active' => array(), 'inactive' => array(), diff --git a/core/modules/menu/menu.module b/core/modules/menu/menu.module index 93c2ed815203f758097997b23850e5d9b6960e88..1b43a4e458ef86db92220379085f0dffbd9d7601 100644 --- a/core/modules/menu/menu.module +++ b/core/modules/menu/menu.module @@ -713,7 +713,7 @@ function menu_get_menus($all = TRUE) { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function menu_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'menu') { diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 23bf4be000e0c40b1352ceee9dcf43efa85f6db2..1e1084e5738ef8b3c0aec53b1d495412c1fa67aa 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1074,7 +1074,7 @@ function node_is_page(EntityInterface $node) { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function node_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'node') { diff --git a/core/modules/search/search.module b/core/modules/search/search.module index f31488be21b7804868eecc2665121105c54ddfdd..efaf0318781381d635fcf98182f7bc62de4d1046 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -135,7 +135,7 @@ function search_permission() { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function search_preprocess_block(&$variables) { if ($variables['plugin_id'] == 'search_form_block') { diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index d1458a85940d23b849e8bb542ae043663102c36e..2da3d2608c15626784628ba2fd7dfe6c9589493a 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -447,7 +447,7 @@ function shortcut_renderable_links($shortcut_set = NULL) { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function shortcut_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'shortcut') { diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index 9d0c19eda66d6a577a61e15959ff71b3e23ec956..7b1528161c4651b044191e341d63af1df74069ff 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -234,7 +234,7 @@ function statistics_update_index() { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function statistics_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'statistics') { diff --git a/core/modules/system/system.module b/core/modules/system/system.module index b3ea7647e37e6d565fb86c1d5c6dbc813193d7ef..cbf9f4475d10cce3e96420773bd2c36b14ecfa39 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2664,7 +2664,7 @@ function system_user_timezone(&$form, &$form_state) { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function system_preprocess_block(&$variables) { // Derive the base plugin ID. diff --git a/core/modules/user/user.module b/core/modules/user/user.module index d02a91ae82e365b5cf3687b8dd120f8e31cb6159..0b884fa5842d69d51977cd3116b3b8a155cda87e 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -646,7 +646,7 @@ function user_validate_current_pass(&$form, &$form_state) { } /** - * Implements hook_preprocess_HOOK() for block.tpl.php. + * Implements hook_preprocess_HOOK() for block.html.twig. */ function user_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'user') {