Problem/Motivation
I ran into this when I tried to use the "Send newsletter issue" action from an ECA model. The action does an access check:
public function access($node, ?AccountInterface $account = NULL, $return_as_object = FALSE) {
if ($node->hasField('simplenews_issue') && $node->simplenews_issue->target_id != NULL) {
return AccessResult::allowedIfHasPermission($account, 'administer newsletters')
->orIf(AccessResult::allowedIfHasPermission($account, 'send newsletter'));
}
return AccessResult::neutral();
}But I got this this error:
TypeError: Drupal\Core\Access\AccessResult::allowedIfHasPermission(): Argument #1 ($account) must be of type Drupal\Core\Session\AccountInterface, null given ...
Steps to reproduce
Just a simple ECA model:
Event: Update content entity, Content: Any Simplenews-enabled node
Action: User, switch current account (account must have permission to administer or send newsletters)
Action: Send newsletter issue, entity: entity (entity is the content entity referenced in the event)
Proposed resolution
The ECA maintainer says the access function needs to provide for the case when the $account variable isn't available, so I added this:
if (!$account) {
$account = \Drupal::currentUser();
}It looks as if the same code is used in StopIssue.php so will include that in a merge request.
Remaining tasks
Merge request pending.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork simplenews-3568037
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
rclemings commentedComment #4
rclemings commentedComment #5
rclemings commentedComment #8
adamps commentedThanks