Problem/Motivation
Error: Call to a member function grantPermission() on null in /Users/vindesh/Sites/ssc_catapult/drupal_app/web/modules/contrib/google_analytics/google_analytics.install on line 19 #0 [internal function]: google_analytics_install(false)
Steps to reproduce
1. If the "Authenticated user" role is not available or deleted.
2. Install google_analytic and you will get the above Error.
Proposed resolution
/**
* Implements hook_install().
*/
function google_analytics_install($is_syncing) {
// Make the default install more user and GDPR friendly.
if (!$is_syncing) {
if($role = Role::load(AccountInterface::AUTHENTICATED_ROLE)) {
$role->grantPermission('opt-in or out of google analytics tracking');
$success = $role->save();
if ($success) {
$messenger = \Drupal::messenger();
$messenger->addMessage(t('Module %module granted %permission permission to authenticated users.', ['%module' => 'Google Analytics', '%permission' => t('Opt-in or out of tracking')]), 'status');
}
}
}
}
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
vindesh commentedComment #3
prudloff commentedComment #4
deepak tomar commentedComment #5
deepak tomar commentedComment #6
deepak tomar commentedComment #7
deepak tomar commentedPatch to fix this issue.