Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ashrafabed created an issue. See original summary.

jhodgdon’s picture

Well, that's very interesting. I see two implementations in core -- one in a test, and one in statistics.module. But I don't see where this hook is invoked. Any ideas?

jhodgdon’s picture

Status: Active » Postponed (maintainer needs more info)
progga’s picture

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Assigned: ashrafabed » Unassigned
Status: Postponed (maintainer needs more info) » Active
Parent issue: » #2509180: [meta] Various plugin definition alter() hooks incorrectly document to use t()

What is a proper place to put this hooks?

Example of usage

/**
 * Implements hook_block_alter().
 */
function example_module_block_alter(&$definitions) {
  foreach ($definitions as $id => $definition) {
    if (strpos($id, 'system_menu_block:') === 0) {
      // Replace $definition properties: id, deriver, class, provider to ones
      // provided by this custom module.
    }
  }
}
andypost’s picture

I think for blocks it makes sense to have separate *.api.php like menu has core/lib/Drupal/Core/Menu/menu.api.php

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

msankhala’s picture

Status: Active » Needs review
FileSize
843 bytes

Here is the patch.

andypost’s picture

Status: Needs review » Needs work
+++ b/core/modules/block/block.api.php
@@ -216,6 +216,22 @@ function hook_block_access(\Drupal\block\Entity\Block $block, $operation, \Drupa
+ * @param $definitions
+ *   The array of block definitions, keyed by plugin ID.

Definitions should be typed, I bet it kinda \Drupal\Component\Plugin\Definition\PluginDefinitionInterface[]|array[] as \Drupal\Core\Plugin\FilteredPluginManagerInterface::getFilteredDefinitions() returns

msankhala’s picture

Status: Needs work » Needs review
FileSize
915 bytes
567 bytes

@ashrafabed Now @param line length is going more than 80 characters. Is it allowed to go more than 80 characters if we specify FQN of the types of param?

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

tanubansal’s picture

Tested #14, hook_block_alter code has been added

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Abhijith S’s picture

FileSize
85.67 KB

Applied patch #14 and it works . The hook_block_alter is correctly documented in the patch

after

Abhijith S’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/block/block.api.php
@@ -216,6 +216,22 @@ function hook_block_access(\Drupal\block\Entity\Block $block, $operation, \Drupa
+ * @param \Drupal\Component\Plugin\Definition\PluginDefinitionInterface[]|array[] $definitions

We know that blocks are not going to be \Drupal\Component\Plugin\Definition\PluginDefinitionInterface[] so only array[] is needed here.

manish-31’s picture

Status: Needs work » Needs review
FileSize
575 bytes
575 bytes

@alexpott removed PluginDefinitionInterface[], needs review.

sulfikar_s’s picture

Hello,

As the patch in #23 failed to apply and found to be not a proper patch. I've created a new patch addressing the comment #22.

Please review.

Vishalghyv’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good to me.

  • catch committed e6cba46 on 9.2.x
    Issue #2717541 by msankhala, manish-31, sulfikar_s, Abhijith S,...

  • catch committed 8afa3d1 on 9.1.x
    Issue #2717541 by msankhala, manish-31, sulfikar_s, Abhijith S,...
catch’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x and cherry-picked to 9.1.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.