You are here

class GaIdService in GA Push 8

Class GaIdService.

Hierarchy

Expanded class hierarchy of GaIdService

1 string reference to 'GaIdService'
ga_push.services.yml in ./ga_push.services.yml
ga_push.services.yml
1 service uses GaIdService
ga_push.google_analytics_id in ./ga_push.services.yml
Drupal\ga_push\GaIdService

File

src/GaIdService.php, line 12

Namespace

Drupal\ga_push
View source
class GaIdService implements GaIdServiceInterface {

  /**
   * Drupal\Core\Config\ConfigManagerInterface definition.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Constructs a new AnalyticsIdService object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_manager
   *   Configuration manager.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   Module handler service.
   */
  public function __construct(ConfigFactoryInterface $config_manager, ModuleHandlerInterface $module_handler) {
    $this->configFactory = $config_manager;
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public function getAnalyticsId() {
    $ga_push = $this->configFactory
      ->get('ga_push.settings');
    $google_analytics_id = $ga_push
      ->get('google_analytics_id');
    if (empty($google_analytics_id) && $this->moduleHandler
      ->moduleExists('google_analytics')) {
      $google_analytics_config = $this->configFactory
        ->get('google_analytics.settings');
      if ($google_analytics_config instanceof ImmutableConfig) {
        $google_analytics_id = $google_analytics_config
          ->get('account');
      }
    }
    return $google_analytics_id;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GaIdService::$configFactory protected property Drupal\Core\Config\ConfigManagerInterface definition.
GaIdService::$moduleHandler protected property Module handler.
GaIdService::getAnalyticsId public function Get the Google Analytics ID. Overrides GaIdServiceInterface::getAnalyticsId
GaIdService::__construct public function Constructs a new AnalyticsIdService object.