function hook_block_alter

Same name and namespace in other branches
  1. 9 core/modules/block/block.api.php \hook_block_alter()
  2. 10 core/modules/block/block.api.php \hook_block_alter()

Allow modules to alter the block plugin definitions.

Parameters

array[] $definitions: The array of block definitions, keyed by plugin ID.

Related topics

14 functions implement hook_block_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

block_block_build_local_actions_block_alter in core/modules/block/block.module
Implements hook_block_build_BASE_BLOCK_ID_alter().
block_content_theme_suggestions_block_alter in core/modules/block_content/block_content.module
Implements hook_theme_suggestions_HOOK_alter() for block templates.
block_test_block_alter in core/modules/block/tests/modules/block_test/block_test.module
Implements hook_block_alter().
help_block_view_help_block_alter in core/modules/help/help.module
Implements hook_block_view_BASE_BLOCK_ID_alter().
layout_builder_plugin_filter_block_alter in core/modules/layout_builder/layout_builder.module
Implements hook_plugin_filter_TYPE_alter().

... See full list

File

core/modules/block/block.api.php, line 228

Code

function hook_block_alter(&$definitions) {
    foreach ($definitions as $id => $definition) {
        if (str_starts_with($id, 'system_menu_block:')) {
            // Replace $definition properties: id, deriver, class, provider to ones
            // provided by this custom module.
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.