You are here

official_facebook_pixel.module in Official Facebook Pixel 7

Same filename and directory in other branches
  1. 8 official_facebook_pixel.module

File

official_facebook_pixel.module
View source
<?php

/*
 * Copyright (C) 2017-present, Facebook, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

/**
 * @file
 * Contains facebook_pixel.module.
 */
use Drupal\official_facebook_pixel\OfficialFacebookPixelInjection;
use Drupal\official_facebook_pixel\OfficialFacebookPixelOptions;
use Drupal\official_facebook_pixel\OfficialFacebookPixelUtils;
use Drupal\official_facebook_pixel\PixelScriptBuilder;

/**
 * Implements hook_permission().
 */
function official_facebook_pixel_permission() {
  return array(
    'admin' => array(
      'title' => t('Official Facebook Pixel Plugin Admin'),
      'description' => t('Official Facebook Pixel plugin admin.'),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function official_facebook_pixel_menu() {
  $items = array();
  $items['admin/config/system/official_facebook_pixel'] = array(
    'title' => t('Official Facebook Pixel Settings'),
    'description' => t('Configure Official Facebook Pixel.'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'official_facebook_pixel_settings_form',
    ),
    'access arguments' => array(
      'admin',
    ),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'official_facebook_pixel.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_page_build().
 */
function official_facebook_pixel_page_build(&$page) {
  if (!should_render()) {
    return;
  }
  $options = OfficialFacebookPixelOptions::getInstance();

  // Return if pixel_id is not positive integer
  if (!OfficialFacebookPixelUtils::isPositiveInteger($options
    ->getPixelId())) {
    return;
  }
  OfficialFacebookPixelInjection::injectPixelCode();
}

/**
 * Check if pixel code should be rendered
 *
 * @return boolean True is should render pixel code, otherwise false.
 */
function should_render() {
  global $user;
  $roles = $user->roles;
  return !(is_array($roles) && in_array("administrator", $roles));
}

Functions

Namesort descending Description
official_facebook_pixel_menu Implements hook_menu().
official_facebook_pixel_page_build Implements hook_page_build().
official_facebook_pixel_permission Implements hook_permission().
should_render Check if pixel code should be rendered