Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pcambra’s picture

Status: Active » Needs review
FileSize
749 bytes
Dave Reid’s picture

It might be good to have a little better example here. Something like if the block is the user login block and the current user is not anonymous, disable access (silly condition since it already does this, but it would at least give something more tangible).

Status: Needs review » Needs work

The last submitted patch, 1892472_document_hook_block_access.patch, failed testing.

jhodgdon’s picture

Please also take a look at the guidelines for documenting hooks:
http://drupal.org/node/1354#hooks

In particular, probably the first line should say "Define access for a block", and the second paragraph should say "This hook is invoked ..." rather than "It is called". It also needs an @return describing what to return and under what conditions.

Also... I definitely agree with #2 - the example should use the global $user I would think, and do something plausible rather than just returning FALSE.

Finally, there should only be one space between the @see and what follows it... and the second @see seems to point to a method that does not exist?

pcambra’s picture

Thanks for the heads up :)
Here's a better patch fixing comments in #4 and with an use example, though I was assuming that examples module would do this kind of stuff.
Hope wording is correct, not native here :)

pcambra’s picture

Status: Needs work » Needs review
jhodgdon’s picture

The Examples project is for giving examples of how to develop modules using various hooks. It is not a substitute for having good hook documentation, including a reasonably realistic example function body.

Anyway, this patch looks much better to me! At least, I thought it was understandable and follows our documentation guidelines. Thanks!

We need to get someone else who is familiar with the new block/plugin system to review the documentation for accuracy and function body to make sure it would do what it says it is doing. I have no idea.

tim.plunkett’s picture

+++ b/core/modules/block/block.api.phpundefined
@@ -99,5 +99,29 @@ function hook_block_view_NAME_alter(array &$build, \Drupal\block\BlockInterface
+ * @param \Drupal\block\BlockInterface $block
...
+function hook_block_access(\Drupal\block\BlockInterface $block) {

This should be \Drupal\block\Plugin\Core\Entity\Block $block, which we've done elsewhere. Ideally it'd be \Drupal\Core\Entity\EntityInterface, but we're not doing that anywhere else.

+++ b/core/modules/block/block.api.phpundefined
@@ -99,5 +99,29 @@ function hook_block_view_NAME_alter(array &$build, \Drupal\block\BlockInterface
+ * @return boolean

@return bool

+++ b/core/modules/block/block.api.phpundefined
@@ -99,5 +99,29 @@ function hook_block_view_NAME_alter(array &$build, \Drupal\block\BlockInterface
+  // Example code that would prevent displaying the 'Powered by drupal' block in

Powered by Drupal, capital D

+++ b/core/modules/block/block.api.phpundefined
@@ -99,5 +99,29 @@ function hook_block_view_NAME_alter(array &$build, \Drupal\block\BlockInterface
+  if ($block->get('plugin') == 'system_powered_by_block' && $block->get('region') <> 'footer') {

This is a fine example, except we use !=, not <>

jhodgdon’s picture

Status: Needs review » Needs work
pcambra’s picture

Status: Needs work » Needs review
FileSize
1.15 KB

This should be \Drupal\block\Plugin\Core\Entity\Block $block, which we've done elsewhere. Ideally it'd be \Drupal\Core\Entity\EntityInterface, but we're not doing that anywhere else.

Fixed, however the other docs in the block.api.php are referencing BlockInterface... shall we fix those in this same patch?

@return bool

There are quite a few "@return boolean" here and there in core, is there a task for fixing those already?

Here's a new patch with comments in #8 fixed.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Both of those things must have been docs we missed in the conversion, but this one is good.

jhodgdon’s picture

Assigned: Unassigned » jhodgdon

Thanks for the new patch and the review! I'll get it committed shortly.

Please file separate issues for a) the other BlockInterface docs and b) @param boolean / @return boolean [I'm not sure if there are @param boolean instances in core but I imagine there are if there are @return boolean], if you haven't already.

pcambra’s picture

About fixing the comments in block.api.php, I think the right issue for this is #1874576: Improve the documentation and naming of hook_block_view_alter() hooks

I've created one for the @param boolean/@return boolean as I didn't find an existing one. #1897058: Replace "boolean" with "bool" when used as param/return/var type

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

jhodgdon’s picture

Assigned: jhodgdon » Unassigned

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