Commit 998e6335 authored by webchick's avatar webchick

Issue #1989568 by Berdir: Remove block config ID from being used as an HTML ID...

Issue #1989568 by Berdir: Remove block config ID from being used as an HTML ID or template suggestion.
parent 06572199
......@@ -313,10 +313,8 @@ function block_theme_suggestions_block(array $variables) {
$suggestions[] = $suggestion .= '__' . strtr($part, '-', '_');
}
if ($id = $variables['elements']['#block']->id()) {
$config_id = explode('.', $id);
$machine_name = array_pop($config_id);
$suggestions[] = 'block__' . $machine_name;
if (!empty($variables['elements']['#id'])) {
$suggestions[] = 'block__' . $variables['elements']['#id'];
}
return $suggestions;
......@@ -363,14 +361,14 @@ function template_preprocess_block(&$variables) {
$variables['content_attributes']['class'][] = 'content';
// Create a valid HTML ID and make sure it is unique.
if ($id = $variables['elements']['#block']->id()) {
$variables['attributes']['id'] = drupal_html_id('block-' . $id);
if (!empty($variables['elements']['#id'])) {
$variables['attributes']['id'] = drupal_html_id('block-' . $variables['elements']['#id']);
}
// Proactively add aria-describedby if possible to improve accessibility.
if (isset($variables['elements']['#block']->subject) && isset($variables['attributes']['role'])) {
$variables['title_attributes']['id'] = drupal_html_id($variables['elements']['#block']->subject);
$variables['attributes']['aria-describedby'] = $variables['title_attributes']['id'];
if ($variables['label'] && isset($variables['attributes']['role'])) {
$variables['title_attributes']['id'] = drupal_html_id($variables['label']);
$variables['attributes']['aria-describedby'] = $variables['title_attributes']['id'];
}
}
......
......@@ -38,7 +38,7 @@ public function view(EntityInterface $entity, $view_mode = 'full', $langcode = N
*/
public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) {
$build = array();
foreach ($entities as $key => $entity) {
foreach ($entities as $entity) {
$entity_id = $entity->id();
$plugin = $entity->getPlugin();
$plugin_id = $plugin->getPluginId();
......@@ -62,7 +62,8 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
'#plugin_id' => $plugin_id,
'#base_plugin_id' => $base_id,
'#derivative_plugin_id' => $derivative_id,
// @todo Remove after fixing http://drupal.org/node/1989568.
'#id' => $entity->id(),
// Add the entity so that it can be used in the #pre_render method.
'#block' => $entity,
);
$build[$entity_id]['#configuration']['label'] = String::checkPlain($configuration['label']);
......@@ -99,9 +100,6 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
$build[$entity_id] = $this->buildBlock($build[$entity_id]);
}
// @todo Remove after fixing http://drupal.org/node/1989568.
$build[$key]['#block'] = $entity;
// Don't run in ::buildBlock() to ensure cache keys can be altered. If an
// alter hook wants to modify the block contents, it can append another
// #pre_render hook.
......@@ -121,6 +119,9 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
*/
public function buildBlock($build) {
$content = $build['#block']->getPlugin()->build();
// Remove the block entity from the render array, to ensure that blocks
// can be rendered without the block config entity.
unset($build['#block']);
if (!empty($content)) {
// Place the $content returned by the block plugin into a 'content' child
// element, as a way to allow the plugin to have complete control of its
......
......@@ -44,10 +44,10 @@ function testBlockThemeHookSuggestions() {
));
$variables = array();
$variables['elements']['#block'] = $block;
$plugin = $block->getPlugin();
$variables['elements']['#configuration'] = $plugin->getConfiguration();
$variables['elements']['#plugin_id'] = $plugin->getPluginId();
$variables['elements']['#id'] = $block->id();
$variables['elements']['#base_plugin_id'] = $plugin->getBasePluginId();
$variables['elements']['#derivative_plugin_id'] = $plugin->getDerivativeId();
$variables['elements']['content'] = array();
......
......@@ -183,6 +183,10 @@ protected function verifyRenderCacheHandling() {
// Rebuild the render array (creating a new cache entry in the process) and
// delete the block to check the cache entry is deleted.
unset($build['#printed']);
// Re-add the block because \Drupal\block\BlockViewBuilder::buildBlock()
// removes it.
$build['#block'] = $this->block;
drupal_render($build);
$this->assertTrue($this->container->get('cache.render')->get($cid), 'The block render element has been cached.');
$this->block->delete();
......
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