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.
public function hasActionAccess($action, AccountInterface $account = NULL) {
if ($action === 'flag' || $action === 'unflag') {
$account = $account ?: \Drupal::currentUser();
return $account->hasPermission($action . ' ' . $this->id);
}
else {
// @todo: Is this the correct response?
return FALSE;
}
}
I'm pretty sure $action can ONLY be one of flag or unflag -- but I can't be entirely sure because the docs are broken: #2415413: errors in docs for hasActionAccess().
I'd say we either don't need the else clause, or we should throw an exception, and I'm leaning towards the former.
Comment | File | Size | Author |
---|---|---|---|
#7 | 2415417.7.removeElseInHasActionAccess.patch | 449 bytes | socketwench |
Comments
Comment #1
webflo CreditAttribution: webflo commentedYou could throw an InvalidArgumentException or LogicException.
Comment #2
socketwench CreditAttribution: socketwench commented$action is a bit tricky. Some modules, like flag_friend, will use a different action (friend/unfriend). This was possible in 7.x-3.x, but it's an open question for 8.x-4.x. Modules like flag_friend would either implement event handling for the action, or provide their own link type -- which is a lot easier now.
Comment #3
socketwench CreditAttribution: socketwench commentedSo really the issue here is if hasActionAccess() is the right API or not. If we only allow flag and unflag, we should have canFlag() and canUnflag() instead. Then we'd need to change flag_entity_view() to use the method.
Comment #4
joachim CreditAttribution: joachim commented> Some modules, like flag_friend, will use a different action (friend/unfriend)
That sounds... crazy :/
Also, I've had a quick look at the code for flag_friend, and I can't actually see any use of that.
Comment #5
socketwench CreditAttribution: socketwench commentedOh, right! I refactored FF so it doesn't do that any longer.
Comment #6
socketwench CreditAttribution: socketwench commentedCreated https://www.drupal.org/node/2417925
Comment #7
socketwench CreditAttribution: socketwench commentedReturning nothing would probably be the better course of action here.
Comment #9
joachim CreditAttribution: joachim commentedCommitted! Thanks!