Skip to content
Snippets Groups Projects

Issue #3349663: Error: Call to a member function grantPermission() on null in userprotect_install()

Merged Issue #3349663: Error: Call to a member function grantPermission() on null in userprotect_install()
+ 14
7
@@ -5,17 +5,24 @@
* Install, update and uninstall functions for the userprotect module.
*/
use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Implements hook_install().
*
* Installs default userprotect permissions for authenticated users.
*/
function userprotect_install() {
$role = \Drupal::entityTypeManager()->getStorage('user_role')->load(AccountInterface::AUTHENTICATED_ROLE);
$role->grantPermission('userprotect.mail.edit');
$role->grantPermission('userprotect.pass.edit');
$role->grantPermission('userprotect.account.edit');
$role->save();
function userprotect_install($is_syncing) {
if ($is_syncing) {
return;
}
$role = Role::load(RoleInterface::AUTHENTICATED_ID);
if ($role instanceof RoleInterface) {
$role->grantPermission('userprotect.mail.edit');
$role->grantPermission('userprotect.pass.edit');
$role->grantPermission('userprotect.account.edit');
$role->trustData()->save();
}
}
Loading