Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291053

ID and NAME are confusing in block_alter hooks

$
0
0

Problem/Motivation

Fixing #1899772: Fix name retrieving for block plugins to fix hook_block_view_NAME_alter() I've realised that ID and NAME on hook_block_view_ID_alter and hook_block_view_NAME_alter are quite confusing to work with.

According to this code (with the fix above included)

      // All blocks, even when empty, should be available for altering.
      $id = str_replace(':', '__', $entity->get('plugin'));
      list(, $name) = explode('.', $entity->id());
      drupal_alter(array('block_view', "block_view_$id", "block_view_$name"), $build[$entity_id], $entity);

$id is actually referring to the plugin, which can be shared by many instances and the $name is actually the id, making the twist extra confusing.

Proposed resolution

Replacing $id and hook_block_view_ID_alter by $plugin and hook_block_view_PLUGIN_alter.
Replacing $name and hook_block_view_NAME_alter by $id and hook_block_view_ID_alter.

Remaining tasks

Once #1899772: Fix name retrieving for block plugins to fix hook_block_view_NAME_alter() gets in, apply the suggested changes in BlockRenderController.php, BlockTest.php, block.api.php and block_test_alter hidden submodule.


Viewing all articles
Browse latest Browse all 291053

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>