Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
d1a88e91
Commit
d1a88e91
authored
May 26, 2013
by
Alex Pott
Browse files
Issue
#1938898
by duellj, Pete B, mlncn: Convert block theme tables to table #type.
parent
477c06c4
Changes
4
Hide whitespace changes
Inline
Side-by-side
core/modules/block/block.admin.inc
View file @
d1a88e91
...
...
@@ -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
;
}
}
core/modules/block/block.module
View file @
d1a88e91
...
...
@@ -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'
,
),
);
}
...
...
core/modules/block/lib/Drupal/block/BlockListController.php
View file @
d1a88e91
...
...
@@ -113,10 +113,6 @@ 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
);
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 @@ public function buildForm(array $form, array &$form_state) {
'#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
,
$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'
][
$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'
][
'#tabledrag'
][]
=
array
(
'order'
,
'sibling'
,
'block-weight'
,
'block-weight-'
.
$region
,
);
$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
,
$form
[
'blocks'
][
$region
]
=
array
(
'#attributes'
=>
array
(
'class'
=>
array
(
'region-title'
,
'region-title-'
.
$region
,
'odd'
),
'no_striping'
=>
TRUE
,
),
);
$links
[
'configure'
]
=
array
(
'title'
=>
t
(
'configure'
),
'href'
=>
'admin/structure/block/manage/'
.
$entity_id
.
'/configure'
,
$form
[
'blocks'
][
$region
][
'title'
]
=
array
(
'#markup'
=>
$region
!=
BLOCK_REGION_NONE
?
$title
:
t
(
'Disabled'
),
'#wrapper_attributes'
=>
array
(
'colspan'
=>
5
,
),
);
$links
[
'delete'
]
=
array
(
'title'
=>
t
(
'delete'
),
'href'
=>
'admin/structure/block/manage/'
.
$entity_id
.
'/delete'
,
$form
[
'blocks'
][
$region
.
'-message'
]
=
array
(
'#attributes'
=>
array
(
'class'
=>
array
(
'region-message'
,
'region-'
.
$region
.
'-message'
,
empty
(
$blocks
[
$region
])
?
'region-empty'
:
'region-populated'
,
),
),
);
$form
[
'blocks'
][
$entity_id
][
'operations'
]
=
array
(
'#type'
=>
'operations'
,
'#links'
=>
$links
,
$form
[
'blocks'
][
$region
.
'-message'
][
'message'
]
=
array
(
'#markup'
=>
'<em>'
.
t
(
'No blocks in this region'
)
.
'</em>'
,
'#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
;
...
...
core/modules/block/templates/block-admin-display-form.html.twig
deleted
100644 → 0
View file @
477c06c4
{#
/**
* @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
}}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment