public function PixelBuilderService::isEnabled in Simple Facebook Pixel 8
Checks if Facebook Pixel should be enabled.
Return value
bool True if enabled, False otherwise.
Overrides PixelBuilderServiceInterface::isEnabled
File
- src/
PixelBuilderService.php, line 190
Class
- PixelBuilderService
- Class PixelBuilderService.
Namespace
Drupal\simple_facebook_pixelCode
public function isEnabled() {
$pixel_enabled = $this->configFactory
->get('simple_facebook_pixel.settings')
->get('pixel_enabled');
$pixel_id = $this->configFactory
->get('simple_facebook_pixel.settings')
->get('pixel_id');
if (!$pixel_enabled || !$pixel_id) {
return FALSE;
}
$is_admin_route = $this->routerAdminContext
->isAdminRoute();
$exclude_admin_pages = $this->configFactory
->get('simple_facebook_pixel.settings')
->get('exclude_admin_pages');
if ($is_admin_route && $exclude_admin_pages) {
return FALSE;
}
$excluded_roles = $this->configFactory
->get('simple_facebook_pixel.settings')
->get('excluded_roles');
$current_user_roles = $this->currentUser
->getRoles();
// If the current user has any of excluded roles, then we are returning
// FALSE, which means that Facebook Pixel will not enabled.
foreach (array_values($excluded_roles) as $user_role) {
if (in_array($user_role, $current_user_roles)) {
return FALSE;
}
}
return TRUE;
}