diff --git a/core/modules/block/block.admin.inc b/core/modules/block/block.admin.inc index 6af9fe398314..78df3fe38c44 100644 --- a/core/modules/block/block.admin.inc +++ b/core/modules/block/block.admin.inc @@ -84,66 +84,3 @@ function block_admin_edit(Block $entity) { return entity_get_form($entity); } -/** - * Prepares variables for block admin display form templates. - * - * Default template: block-admin-display-form.html.twig. - * - * @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']; - if (isset($variables['block_regions'][BLOCK_REGION_NONE])) { - $variables['block_regions'][BLOCK_REGION_NONE] = t('Disabled'); - } - - foreach ($variables['block_regions'] as $key => $value) { - // Initialize an empty array for the region. - $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(); - - // Add each block in the form to the appropriate place in the block listing. - foreach (element_children($variables['form']['blocks']) as $i) { - $block = &$variables['form']['blocks'][$i]; - - // Fetch the region for the current block. - $region = (isset($block['region']['#default_value']) ? $block['region']['#default_value'] : BLOCK_REGION_NONE); - - // Set special classes needed for table drag and drop. - $block['region']['#attributes']['class'] = array('block-region-select', 'block-region-' . $region); - $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 = $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; - } -} diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 8b24c9d91d6e..34d09055b5f2 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -92,11 +92,6 @@ function block_theme() { 'render element' => 'elements', 'template' => 'block', ), - 'block_admin_display_form' => array( - 'template' => 'block-admin-display-form', - 'file' => 'block.admin.inc', - 'render element' => 'form', - ), ); } diff --git a/core/modules/block/lib/Drupal/block/BlockListController.php b/core/modules/block/lib/Drupal/block/BlockListController.php index 5b18b3c69a0f..f940b06296bf 100644 --- a/core/modules/block/lib/Drupal/block/BlockListController.php +++ b/core/modules/block/lib/Drupal/block/BlockListController.php @@ -113,10 +113,6 @@ class BlockListController extends ConfigEntityListController implements FormInte // Add a last region for disabled blocks. $block_regions_with_disabled = $this->regions + array(BLOCK_REGION_NONE => BLOCK_REGION_NONE); - foreach ($block_regions_with_disabled as $region => $title) { - $form['#attached']['drupal_add_tabledrag'][] = array('blocks', 'match', 'sibling', 'block-region-select', 'block-region-' . $region, NULL, FALSE); - $form['#attached']['drupal_add_tabledrag'][] = array('blocks', 'order', 'sibling', 'block-weight', 'block-weight-' . $region); - } $form['block_regions'] = array( '#type' => 'value', '#value' => $block_regions_with_disabled, @@ -132,46 +128,131 @@ class BlockListController extends ConfigEntityListController implements FormInte '#type' => 'value', '#value' => $this->theme, ); - $form['blocks'] = array(); - $form['#tree'] = TRUE; + $form['blocks'] = array( + '#type' => 'table', + '#header' => array( + t('Block'), + t('Region'), + t('Weight'), + t('Operations'), + ), + '#attributes' => array( + 'id' => 'blocks', + ), + ); + // Build blocks first for each region. foreach ($entities as $entity_id => $entity) { $info = $entity->getPlugin()->getDefinition(); - $form['blocks'][$entity_id]['info'] = array( - '#markup' => check_plain($info['admin_label']), - ); - $form['blocks'][$entity_id]['theme'] = array( - '#type' => 'hidden', - '#value' => $this->theme, - ); - $form['blocks'][$entity_id]['weight'] = array( - '#type' => 'weight', - '#default_value' => $entity->get('weight'), - '#delta' => $weight_delta, - '#title_display' => 'invisible', - '#title' => t('Weight for @block block', array('@block' => $info['admin_label'])), - ); - $form['blocks'][$entity_id]['region'] = array( - '#type' => 'select', - '#default_value' => $entity->get('region') != BLOCK_REGION_NONE ? $entity->get('region') : NULL, - '#empty_value' => BLOCK_REGION_NONE, - '#title_display' => 'invisible', - '#title' => t('Region for @block block', array('@block' => $info['admin_label'])), - '#options' => $this->regions, - ); - $links['configure'] = array( - 'title' => t('configure'), - 'href' => 'admin/structure/block/manage/' . $entity_id . '/configure', - ); - $links['delete'] = array( - 'title' => t('delete'), - 'href' => 'admin/structure/block/manage/' . $entity_id . '/delete', - ); - $form['blocks'][$entity_id]['operations'] = array( - '#type' => 'operations', - '#links' => $links, - ); + $info['entity_id'] = $entity_id; + $blocks[$entity->get('region')][] = $info; } + + // Loop over each region and build blocks. + foreach ($block_regions_with_disabled as $region => $title) { + $form['blocks']['#tabledrag'][] = array( + 'match', + 'sibling', + 'block-region-select', + 'block-region-' . $region, + NULL, + FALSE, + ); + $form['blocks']['#tabledrag'][] = array( + 'order', + 'sibling', + 'block-weight', + 'block-weight-' . $region, + ); + + $form['blocks'][$region] = array( + '#attributes' => array( + 'class' => array('region-title', 'region-title-' . $region, 'odd'), + 'no_striping' => TRUE, + ), + ); + $form['blocks'][$region]['title'] = array( + '#markup' => $region != BLOCK_REGION_NONE ? $title : t('Disabled'), + '#wrapper_attributes' => array( + 'colspan' => 5, + ), + ); + + $form['blocks'][$region . '-message'] = array( + '#attributes' => array( + 'class' => array( + 'region-message', + 'region-' . $region . '-message', + empty($blocks[$region]) ? 'region-empty' : 'region-populated', + ), + ), + ); + $form['blocks'][$region . '-message']['message'] = array( + '#markup' => '' . t('No blocks in this region') . '', + '#wrapper_attributes' => array( + 'colspan' => 5, + ), + ); + + if (isset($blocks[$region])) { + foreach ($blocks[$region] as $info) { + $entity_id = $info['entity_id']; + + $form['blocks'][$entity_id] = array( + '#attributes' => array( + 'class' => array('draggable'), + ), + ); + + $form['blocks'][$entity_id]['info'] = array( + '#markup' => check_plain($info['admin_label']), + '#wrapper_attributes' => array( + 'class' => array('block'), + ), + ); + $form['blocks'][$entity_id]['region-theme']['region'] = array( + '#type' => 'select', + '#default_value' => $region, + '#empty_value' => BLOCK_REGION_NONE, + '#title_display' => 'invisible', + '#title' => t('Region for @block block', array('@block' => $info['admin_label'])), + '#options' => $this->regions, + '#attributes' => array( + 'class' => array('block-region-select', 'block-region-' . $region), + ), + '#parents' => array('blocks', $entity_id, 'region'), + ); + $form['blocks'][$entity_id]['region-theme']['theme'] = array( + '#type' => 'hidden', + '#value' => $this->theme, + '#parents' => array('blocks', $entity_id, 'theme'), + ); + $form['blocks'][$entity_id]['weight'] = array( + '#type' => 'weight', + '#default_value' => $entity->get('weight'), + '#delta' => $weight_delta, + '#title_display' => 'invisible', + '#title' => t('Weight for @block block', array('@block' => $info['admin_label'])), + '#attributes' => array( + 'class' => array('block-weight', 'block-weight-' . $region), + ), + ); + $links['configure'] = array( + 'title' => t('configure'), + 'href' => 'admin/structure/block/manage/' . $entity_id . '/configure', + ); + $links['delete'] = array( + 'title' => t('delete'), + 'href' => 'admin/structure/block/manage/' . $entity_id . '/delete', + ); + $form['blocks'][$entity_id]['operations'] = array( + '#type' => 'operations', + '#links' => $links, + ); + } + } + } + // Do not allow disabling the main system content block when it is present. if (isset($form['blocks']['system_main']['region'])) { $form['blocks']['system_main']['region']['#required'] = TRUE; diff --git a/core/modules/block/templates/block-admin-display-form.html.twig b/core/modules/block/templates/block-admin-display-form.html.twig deleted file mode 100644 index 545a06cca447..000000000000 --- a/core/modules/block/templates/block-admin-display-form.html.twig +++ /dev/null @@ -1,56 +0,0 @@ -{# -/** - * @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 }}