Commit bd5769d9 authored by alexpott's avatar alexpott

Issue #1898034 by Cottser, jenlampton, joelpittet, Shawn DeArmond, idflood,...

Issue #1898034 by Cottser, jenlampton, joelpittet, Shawn DeArmond, idflood, Hydra, artofeclipse, rich.yumul, chrisjlee, gnuget, c4rl, thund3rbox: block.module - Convert PHPTemplate templates to Twig.
parent 6b4b127e
......@@ -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']);
}
......@@ -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
......
......@@ -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;
}
}
......
......@@ -135,11 +135,13 @@ protected function renderTests() {
$entity = entity_load('block', 'stark.test_block');
$output = entity_view($entity, 'block');
$expected = array();
$expected[] = ' <div id="block-test-block" class="block block-block-test">';
$expected[] = '';
$expected[] = '<div class="block block-block-test" id="block-test-block">';
$expected[] = ' ';
$expected[] = ' ';
$expected[] = '';
$expected[] = ' <div class="content">';
$expected[] = ' </div>';
$expected[] = ' ';
$expected[] = ' </div>';
$expected[] = '</div>';
$expected[] = '';
$expected_output = implode("\n", $expected);
......@@ -159,12 +161,14 @@ protected function renderTests() {
$entity->save();
$output = entity_view($entity, 'block');
$expected = array();
$expected[] = ' <div id="block-test-block2" class="block block-block-test">';
$expected[] = '';
$expected[] = ' <h2>Powered by Bananas</h2>';
$expected[] = '<div class="block block-block-test" id="block-test-block2">';
$expected[] = ' ';
$expected[] = ' <h2>Powered by Bananas</h2>';
$expected[] = ' ';
$expected[] = '';
$expected[] = ' <div class="content">';
$expected[] = ' </div>';
$expected[] = ' ';
$expected[] = ' </div>';
$expected[] = '</div>';
$expected[] = '';
$expected_output = implode("\n", $expected);
......
{#
/**
* @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
*/
#}
<table id="blocks" class="sticky-enabled">
<thead>
<tr>
<th>{{ 'Block'|t }}</th>
<th>{{ 'Region'|t }}</th>
<th>{{ 'Weight'|t }}</th>
<th>{{ 'Operations'|t }}</th>
</tr>
</thead>
<tbody>
{% set row = 0 %}
{% for region, title in block_regions %}
<tr class="region-title region-title-{{ region }}">
<td colspan="5">{{ title }}</td>
</tr>
<tr class="region-message region-{{ region }}-message {{ block_listing[region] is empty ? 'region-empty' : 'region-populated' }}">
<td colspan="5"><em>{{ 'No blocks in this region'|t }}</em></td>
</tr>
{% for delta, data in block_listing[region] %}
<tr{{ data.attributes }}>
<td class="block">{{ data.block_title }}</td>
<td>{{ data.region_select }}</td>
<td>{{ data.weight_select }}</td>
<td>{{ data.operations }}</td>
</tr>
{% set row = row + 1 %}
{% endfor %}
{% endfor %}
</tbody>
</table>
{{ form }}
<?php
/**
* @file
* Default theme implementation to configure blocks.
*
* Available variables:
* - $block_regions: An array of regions. Keyed by name with the title as value.
* - $block_listing: An array of blocks keyed by region and then delta.
* - $form_submit: Form submit button.
*
* Each $block_listing[$region] contains an array of blocks for that region.
*
* Each $data in $block_listing[$region] contains:
* - $data->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
*/
?>
<table id="blocks" class="sticky-enabled">
<thead>
<tr>
<th><?php print t('Block'); ?></th>
<th><?php print t('Region'); ?></th>
<th><?php print t('Weight'); ?></th>
<th><?php print t('Operations'); ?></th>
</tr>
</thead>
<tbody>
<?php $row = 0; ?>
<?php foreach ($block_regions as $region => $title): ?>
<tr class="region-title region-title-<?php print $region?>">
<td colspan="5"><?php print $title; ?></td>
</tr>
<tr class="region-message region-<?php print $region?>-message <?php print empty($block_listing[$region]) ? 'region-empty' : 'region-populated'; ?>">
<td colspan="5"><em><?php print t('No blocks in this region'); ?></em></td>
</tr>
<?php foreach ($block_listing[$region] as $delta => $data): ?>
<tr class="draggable <?php print $row % 2 == 0 ? 'odd' : 'even'; ?><?php print $data->row_class ? ' ' . $data->row_class : ''; ?>">
<td class="block"><?php print $data->block_title; ?></td>
<td><?php print $data->region_select; ?></td>
<td><?php print $data->weight_select; ?></td>
<td><?php print $data->operations; ?></td>
</tr>
<?php $row++; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
<?php print $form_submit; ?>
{#
/**
* @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.
#}
<div{{ attributes }}>
{{ title_prefix }}
{% if label %}
<h2{{ title_attributes }}>{{ label }}</h2>
{% endif %}
{{ title_suffix }}
<div{{ content_attributes }}>
{{ content }}
</div>
</div>
<?php
/**
* @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: An array 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.
* - $content: Block content.
* - $attributes: An instance of Attributes class that can be manipulated as an
* array and printed as a string.
* It includes the 'class' information, which includes:
* - 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_prefix (array): An array containing additional output populated by
* modules, intended to be displayed in front of the main title tag that
* appears in the template.
* - $title_suffix (array): An array containing additional output populated by
* modules, intended to be displayed after the main title tag that appears in
* the template.
*
* Helper variables:
* - $is_front: Flags true when presented in the front page.
* - $logged_in: Flags true when the current user is a logged-in member.
* - $is_admin: Flags true when the current user is an administrator.
* - $block_html_id: A valid HTML ID and guaranteed unique.
*
* @see template_preprocess()
* @see template_preprocess_block()
* @see template_process()
*
* @ingroup themeable
*/
?>
<?php if (isset($block_html_id)): ?>
<div id="<?php print $block_html_id; ?>" <?php print $attributes; ?>>
<?php else: ?>
<div <?php print $attributes; ?>>
<?php endif; ?>
<?php print render($title_prefix); ?>
<?php if ($label): ?>
<h2<?php print $title_attributes; ?>><?php print $label; ?></h2>
<?php endif;?>
<?php print render($title_suffix); ?>
<div<?php print $content_attributes; ?>>
<?php print render($content) ?>
</div>
</div>
......@@ -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') {
......
......@@ -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') {
......
......@@ -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.
*/
......
......@@ -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') {
......
......@@ -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') {
......
......@@ -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') {
......
......@@ -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(),
......
......@@ -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') {
......
......@@ -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') {
......
......@@ -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') {
......
......@@ -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') {
......
......@@ -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') {
......
......@@ -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.
......
......@@ -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') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment