I am newbie and working on Drupal-7.
I have created custom block module called 'mycampaign' to add script to Retargeting Tags into each page.
Script:
<script async src="http://i.simpli.fi/dpx.js?cid=0&segment=Segment+Name&campaign_id=0"></script>
But, I am getting this error:
Warning: file_get_contents(\sites\all\modules\mycampaign\mycampaign.js\mycampaign.js) [function.file-get-contents]: failed to open stream: No such file or directory in drupal_build_js_cache() (line 5008 of /mnt/www/html/xyzexample/docroot/includes/common.inc).
Appreciate your help!
.info file for my custom module
name = mycampaign
description = This module provides a custom block with dynamic content.
package = MyModules
core = 7.x
; NEW LINE
configure = admin/config/content/mycampaign
scripts[] = mycampaign.js
File code from my custom module:
<?php
/**
* Implements hook_help().
*
* Displays help and module information.
*
* @param path
* Which path of the site we're using to display help
* @param arg
* Array that holds the current path as returned from arg() function
*/
/**
* Implements hook_block_info().
*/
function mycampaign_help($path, $arg) {
switch ($path) {
case "admin/help#mycampaign":
return '<p>' . t("Displays links to nodes created on this date") . '</p>';
break;
}
}
/**
* Declaring the block
*/
function mycampaign_block_info() {
$blocks['mycampaign'] = array(
// The name that will appear in the block list.
'info' => t('mycampaign'),
// Default setting.
'cache' => DRUPAL_CACHE_PER_ROLE,
);
return $blocks;
}
function mycampaign_block_view($delta = ' ') {
if ($delta == 'mycampaign_delta') {
$block = array(
'subject' => t('mycampaign block title'),
'content' => array(
'#markup' => '<p>' . t('mycampaign block output.') . '</p>',
'#attached' => array(
'js' => array('\sites\all\modules\mycampaign\mycampaign.js'),
),
),
drupal_add_html_head($viewport, 'viewport')
);
return $block;
}
}
/**
* Implements hook_menu().
*/
function mycampaign_menu() {
// $items = array();
$items['admin/config/content/mycampaign'] = array(
'title' => 'My Campaign',
'description' => 'Configuration for My Campaign module',
// 'page callback' => '_mycampaign_page',
'page arguments' => array('mycampaign_form'),
'access arguments' => array('access mycampaign content'),
'type' => MENU_NORMAL_ITEM, //Will appear in Navigation menu.
);
return $items;
}
function mycampaign_init(){
drupal_add_js(drupal_get_path('mycampaign', 'mycampaign').'\sites\all\modules\mycampaign\mycampaign.js\mycampaign.js');
}
/**
* Creating the configuration form
*/
function mycampaign_contents() {
//Get today's date.
$today = getdate();
//Calculate midnight a week ago.
$start_time = mktime(0, 0, 0,$today['mon'],($today['mday'] - 7), $today['year']);
//Get all posts from one week ago to the present.
$end_time = time();
//NEW LINE
$max_num = variable_get('mycampaign_max', 3);
//Use Database API to retrieve my campaign.
$query = db_select('node', 'n')
->fields('n', array('nid', 'title', 'created'))
->condition('status', 1) //Published.
->condition('created', array($start_time, $end_time), 'BETWEEN')
->orderBy('created', 'DESC') //Most recent first.
->range(0, $max_num) //NEW LINE
->execute();
return $query;
}
/**
* Validating the data
*/
/**
* Implements validation from the Form API.
*
* @param $form
* A structured array containing the elements and properties of the form.
* @param $form_state
* An array that stores information about the form's current state
* during processing.
*/
function mycampaign_form_validate($form, &$form_state){
$max_num = $form_state['values']['mycampaign_max'];
if (!is_numeric($max_num)){
form_set_error('mycampaign_max', t('You must enter a number for the maximum number of posts to display.'));
}
elseif ($max_num <= 0){
form_set_error('mycampaign_max', t('Maximum number of posts to display must be positive.'));
}
}
/**
* Specifying a custom permission for a new page
* Implements hook_permission().
*/
function mycampaign_permission() {
return array(
'access mycampaign content' => array(
'title' => t('Access content for the mycampaign module'),
)
);
}
/**
* Implements hook_menu().
*/
/*
function mycampaign_menu() {
$items = array();
$items['mycampaign'] = array(
'title' => 'My Campaign',
'page callback' => '_mycampaign_page',
'access arguments' => array('access mycampaign content'),
'type' => MENU_NORMAL_ITEM, //Will appear in Navigation menu.
);
return $items;
}
* */
And script in JS file
<script async src="http://i.simpli.fi/dpx.js?cid=0&segment=Segment+Name&campaign_id=0"></script>