Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
No way to display user created menus for anonymous users.
This is a followup for #1535868: Convert all blocks into plugins.
SystemMenuBlock
has the following method:
public function access(AccountInterface $account) {
$derivative = $this->getDerivativeId();
return ($account->isAuthenticated() || in_array($derivative, array('main', 'tools', 'footer')));
}
Special-casing two particular menus that happen to be provided with the Standard profile is probably not best practice.
Proposed resolution
Get rid of this access check because menu links does this.
This issue should probably be resolved when block access is moved to access plugins for layouts; however, if that conversion does not happen, it should be fixed in another way.
Comment | File | Size | Author |
---|---|---|---|
#11 | 1874564-menu-block-access-11.patch | 777 bytes | andypost |
Comments
Comment #1
xjmComment #2
xjmComment #3
jibranand what is that.
Comment #3.0
jibranRemoving myself from the author field so that I can unfollow. --xjm
Comment #4
andypostThis is a regression that user created menus only visible for authorized users only.
So better remove this ugly logic because menu link access system covers that
Comment #5
dawehnerIt would be great to have some test coverage maybe for that?
Comment #6
andypostAny idea for test? we have a lot tests that checks menu link access so I see no reason
Comment #8
jibran4: 1874564-menu-block-access-4.patch queued for re-testing.
Comment #9
jrockowitz CreditAttribution: jrockowitz commentedThe patch works for me. It makes complete sense that a SystemMenuBlock::access() handler is not needed and the default block/menu link access controls is what should be used to limit access to a menu for anonymous users.
I am also unclear what tests needed to be created since this patch is removing a feature and relying the block modules access controls which I am assuming has test coverage.
Comment #10
benjy CreditAttribution: benjy commentedNeeds a reroll
Comment #11
andypostRe-roll, I still see no reason for tests
Comment #12
benjy CreditAttribution: benjy commentedI tested and this fixes the issue with anonymous users not been able to see user created menu's. Also the menu/menu link system does seem to have sufficient tests. Unless someone can suggest another test to add this should be RTBC.
Comment #13
webchickYeah, this looks fine. The only test I can think of would be specific to these particular blocks, but that doesn't make much sense.
Committed and pushed to 8.x. Thanks!
Comment #15
xjm