Commit 1c545591 authored by Dries's avatar Dries

Issue #2079761 by tim.plunkett: Use a template for the block listing page to simplify the form.

parent 813d0d8e
......@@ -89,6 +89,10 @@ function block_theme() {
'render element' => 'elements',
'template' => 'block',
),
'block_list' => array(
'render element' => 'form',
'template' => 'block-list',
),
);
}
......
......@@ -32,12 +32,12 @@ a.block-demo-backlink:hover {
text-decoration: underline;
}
.block-list-region {
.layout-region {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.block-list-right {
.block-list-secondary {
border: 1px solid #bfbfbf;
border-bottom-width: 0;
}
......@@ -52,7 +52,7 @@ a.block-demo-backlink:hover {
.block-list a:before {
content: '+ ';
}
.block-list-right .form-type-search {
.block-list-secondary .form-type-search {
padding: 0 1em;
}
......@@ -61,35 +61,35 @@ a.block-demo-backlink:hover {
screen and (min-width: 780px),
(orientation: landscape) and (min-device-height: 780px) {
.block-list-left {
.block-list-primary {
float: left; /* LTR */
width: 75%;
padding-right: 2em;
}
[dir="rtl"] .block-list-left {
[dir="rtl"] .block-list-primary {
float: right;
padding-left: 2em;
padding-right: 0;
}
.block-list-right {
.block-list-secondary {
float: right; /* LTR */
width: 25%;
}
[dir="rtl"] .block-list-right {
[dir="rtl"] .block-list-secondary {
float: left;
}
/* @todo File an issue to add a standard class to all text-like inputs */
.block-list-right .form-autocomplete,
.block-list-right .form-text,
.block-list-right .form-tel,
.block-list-right .form-email,
.block-list-right .form-url,
.block-list-right .form-search,
.block-list-right .form-number,
.block-list-right .form-color,
.block-list-right textarea {
.block-list-secondary .form-autocomplete,
.block-list-secondary .form-text,
.block-list-secondary .form-tel,
.block-list-secondary .form-email,
.block-list-secondary .form-url,
.block-list-secondary .form-search,
.block-list-secondary .form-number,
.block-list-secondary .form-color,
.block-list-secondary textarea {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
......@@ -108,8 +108,8 @@ screen and (min-width: 780px),
screen and (max-width: 1020px),
(orientation: landscape) and (max-device-height: 1020px) {
.toolbar-vertical .block-list-left,
.toolbar-vertical .block-list-right {
.toolbar-vertical .block-list-primary,
.toolbar-vertical .block-list-secondary {
float: none;
width: auto;
padding-right: 0;
......
......@@ -120,6 +120,7 @@ public function getFormID() {
*/
public function buildForm(array $form, array &$form_state) {
$entities = $this->load();
$form['#theme'] = array('block_list');
$form['#attached']['library'][] = array('system', 'drupal.tableheader');
$form['#attached']['library'][] = array('block', 'drupal.block');
$form['#attached']['library'][] = array('block', 'drupal.block.admin');
......@@ -127,13 +128,7 @@ public function buildForm(array $form, array &$form_state) {
// Add a last region for disabled blocks.
$block_regions_with_disabled = $this->regions + array(BLOCK_REGION_NONE => BLOCK_REGION_NONE);
$form['left']['#type'] = 'container';
$form['left']['#attributes']['class'] = array(
'block-list-region',
'block-list-left',
);
$form['left']['block_regions'] = array(
$form['block_regions'] = array(
'#type' => 'value',
'#value' => $block_regions_with_disabled,
);
......@@ -144,11 +139,11 @@ public function buildForm(array $form, array &$form_state) {
$weight_delta = round(count($entities) / 2);
// Build the form tree.
$form['left']['edited_theme'] = array(
$form['edited_theme'] = array(
'#type' => 'value',
'#value' => $this->theme,
);
$form['left']['blocks'] = array(
$form['blocks'] = array(
'#type' => 'table',
'#header' => array(
t('Block'),
......@@ -174,7 +169,7 @@ public function buildForm(array $form, array &$form_state) {
// Loop over each region and build blocks.
foreach ($block_regions_with_disabled as $region => $title) {
$form['left']['blocks']['#tabledrag'][] = array(
$form['blocks']['#tabledrag'][] = array(
'match',
'sibling',
'block-region-select',
......@@ -182,27 +177,27 @@ public function buildForm(array $form, array &$form_state) {
NULL,
FALSE,
);
$form['left']['blocks']['#tabledrag'][] = array(
$form['blocks']['#tabledrag'][] = array(
'order',
'sibling',
'block-weight',
'block-weight-' . $region,
);
$form['left']['blocks'][$region] = array(
$form['blocks'][$region] = array(
'#attributes' => array(
'class' => array('region-title', 'region-title-' . $region, 'odd'),
'no_striping' => TRUE,
),
);
$form['left']['blocks'][$region]['title'] = array(
$form['blocks'][$region]['title'] = array(
'#markup' => $region != BLOCK_REGION_NONE ? $title : t('Disabled'),
'#wrapper_attributes' => array(
'colspan' => 5,
),
);
$form['left']['blocks'][$region . '-message'] = array(
$form['blocks'][$region . '-message'] = array(
'#attributes' => array(
'class' => array(
'region-message',
......@@ -211,7 +206,7 @@ public function buildForm(array $form, array &$form_state) {
),
),
);
$form['left']['blocks'][$region . '-message']['message'] = array(
$form['blocks'][$region . '-message']['message'] = array(
'#markup' => '<em>' . t('No blocks in this region') . '</em>',
'#wrapper_attributes' => array(
'colspan' => 5,
......@@ -222,19 +217,19 @@ public function buildForm(array $form, array &$form_state) {
foreach ($blocks[$region] as $info) {
$entity_id = $info['entity_id'];
$form['left']['blocks'][$entity_id] = array(
$form['blocks'][$entity_id] = array(
'#attributes' => array(
'class' => array('draggable'),
),
);
$form['left']['blocks'][$entity_id]['info'] = array(
$form['blocks'][$entity_id]['info'] = array(
'#markup' => check_plain($info['admin_label']),
'#wrapper_attributes' => array(
'class' => array('block'),
),
);
$form['left']['blocks'][$entity_id]['region-theme']['region'] = array(
$form['blocks'][$entity_id]['region-theme']['region'] = array(
'#type' => 'select',
'#default_value' => $region,
'#empty_value' => BLOCK_REGION_NONE,
......@@ -246,12 +241,12 @@ public function buildForm(array $form, array &$form_state) {
),
'#parents' => array('blocks', $entity_id, 'region'),
);
$form['left']['blocks'][$entity_id]['region-theme']['theme'] = array(
$form['blocks'][$entity_id]['region-theme']['theme'] = array(
'#type' => 'hidden',
'#value' => $this->theme,
'#parents' => array('blocks', $entity_id, 'theme'),
);
$form['left']['blocks'][$entity_id]['weight'] = array(
$form['blocks'][$entity_id]['weight'] = array(
'#type' => 'weight',
'#default_value' => $info['weight'],
'#delta' => $weight_delta,
......@@ -261,33 +256,27 @@ public function buildForm(array $form, array &$form_state) {
'class' => array('block-weight', 'block-weight-' . $region),
),
);
$form['left']['blocks'][$entity_id]['operations'] = $this->buildOperations($info['entity']);
$form['blocks'][$entity_id]['operations'] = $this->buildOperations($info['entity']);
}
}
}
// Do not allow disabling the main system content block when it is present.
if (isset($form['left']['blocks']['system_main']['region'])) {
$form['left']['blocks']['system_main']['region']['#required'] = TRUE;
if (isset($form['blocks']['system_main']['region'])) {
$form['blocks']['system_main']['region']['#required'] = TRUE;
}
$form['left']['actions'] = array(
$form['actions'] = array(
'#tree' => FALSE,
'#type' => 'actions',
);
$form['left']['actions']['submit'] = array(
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save blocks'),
'#button_type' => 'primary',
);
$form['right']['#type'] = 'container';
$form['right']['#attributes']['class'] = array(
'block-list-region',
'block-list-right',
);
$form['right']['title'] = array(
$form['place_blocks']['title'] = array(
'#type' => 'container',
'#children' => '<h3>' . t('Place blocks') . '</h3>',
'#attributes' => array(
......@@ -297,7 +286,7 @@ public function buildForm(array $form, array &$form_state) {
),
);
$form['right']['filter'] = array(
$form['place_blocks']['filter'] = array(
'#type' => 'search',
'#title' => t('Filter'),
'#title_display' => 'invisible',
......@@ -310,8 +299,8 @@ public function buildForm(array $form, array &$form_state) {
),
);
$form['right']['list']['#type'] = 'container';
$form['right']['list']['#attributes']['class'][] = 'entity-meta';
$form['place_blocks']['list']['#type'] = 'container';
$form['place_blocks']['list']['#attributes']['class'][] = 'entity-meta';
// Sort the plugins first by category, then by label.
$plugins = $this->blockManager->getDefinitions();
......@@ -323,8 +312,8 @@ public function buildForm(array $form, array &$form_state) {
});
foreach ($plugins as $plugin_id => $plugin_definition) {
$category = $plugin_definition['category'];
if (!isset($form['right']['list'][$category])) {
$form['right']['list'][$category] = array(
if (!isset($form['place_blocks']['list'][$category])) {
$form['place_blocks']['list'][$category] = array(
'#type' => 'details',
'#title' => $category,
'content' => array(
......@@ -338,7 +327,7 @@ public function buildForm(array $form, array &$form_state) {
),
);
}
$form['right']['list'][$category]['content']['#links'][$plugin_id] = array(
$form['place_blocks']['list'][$category]['content']['#links'][$plugin_id] = array(
'title' => $plugin_definition['admin_label'],
'href' => 'admin/structure/block/add/' . $plugin_id . '/' . $this->theme,
'attributes' => array(
......
{#
/**
* @file
* Two column template for the block add/edit form.
*
* This template will be used when a block edit form specifies 'block_edit_form'
* as its #theme callback. Otherwise, by default, block add/edit forms will be
* themed by theme_form().
*
* Available variables:
* - form: The block add/edit form.
*
* @ingroup themeable
*/
#}
{% hide(form.place_blocks) %}
<div class="layout-block-list clearfix">
<div class="layout-region block-list-primary">
{{ form }}
</div>
<div class="layout-region block-list-secondary">
{{ form.place_blocks }}
</div>
</div>
......@@ -1763,7 +1763,7 @@ details.fieldset-no-legend {
screen and (max-width: 1020px),
(orientation: landscape) and (max-device-height: 1020px) {
.toolbar-vertical .block-list-right,
.toolbar-vertical .block-list-secondary,
.toolbar-vertical .layout-region-node-secondary {
margin-bottom: 0;
padding-bottom: 0;
......
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