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)

Created on 11 March 2025, about 1 month ago

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

When we will install google_analytic then it's through 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

🐛 Bug report
Status

Active

Version

4.0

Component

Code

Created by

🇮🇳India vindesh Indore

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024