class UpdateThreadAccess in Opigno messaging 3.x
Check if the user can edit the given PM thread.
@package Drupal\opigno_messaging\Access
Hierarchy
- class \Drupal\opigno_messaging\Access\UpdateThreadAccess implements AccessInterface
Expanded class hierarchy of UpdateThreadAccess
1 string reference to 'UpdateThreadAccess'
1 service uses UpdateThreadAccess
File
- src/
Access/ UpdateThreadAccess.php, line 17
Namespace
Drupal\opigno_messaging\AccessView source
class UpdateThreadAccess implements AccessInterface {
/**
* Checks the access.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check the access to.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in user's account.
* @param \Drupal\private_message\Entity\PrivateMessageThreadInterface $private_message_thread
* The thread to check the access to.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(Route $route, AccountInterface $account, PrivateMessageThreadInterface $private_message_thread) : AccessResultInterface {
if (!$private_message_thread
->hasField('field_author')) {
return AccessResult::forbidden();
}
// Only group discussions can be edited be the author.
$owner = (int) $private_message_thread
->get('field_author')
->getString();
$is_group = count($private_message_thread
->getMembers()) > 2;
return AccessResult::allowedIf($is_group && $owner === (int) $account
->id());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UpdateThreadAccess:: |
public | function | Checks the access. |