function datalayer_add in dataLayer 7
Same name and namespace in other branches
- 8 datalayer.module \datalayer_add()
Allow adding to the data layer easy on the fly, similar to drupal_add_js().
Passing empty params will return current dataLayer output.
Parameters
array $data: An array of dataLayer data keyed by variable name (optional).
bool $overwrite: If data should overwrite existing dataLayer vars of same name (optional).
Return value
array All data layer data added thus far.
5 calls to datalayer_add()
- DataLayerUnitTests::testDataLayerAddDoesNotOverwriteByDefault in tests/
datalayer.unit.test - Test DataLayer Add Does Not Overwrite By Default.
- DataLayerUnitTests::testDataLayerAddWillAddData in tests/
datalayer.unit.test - Test DataLayer Add Will Add Data.
- DataLayerUnitTests::testDataLayerAddWillOverwriteWithFlag in tests/
datalayer.unit.test - Test DataLayer Add Will Overwrite With Flag.
- datalayer_preprocess_html in ./
datalayer.module - Implements hook_preprocess_HOOK().
- datalayer_preprocess_page in ./
datalayer.module - Implements hook_preprocess_HOOK().
1 string reference to 'datalayer_add'
- DataLayerUnitTests::setupEmptyDataLayer in tests/
datalayer.unit.test - Setup empty datalayer.
File
- ./
datalayer.module, line 344 - Client-side data space.
Code
function datalayer_add(array $data = array(), $overwrite = FALSE) {
$output_data =& drupal_static(__FUNCTION__, _datalayer_defaults());
// If we've been given data, add it to the output.
if (!empty($data)) {
if ($overwrite) {
$output_data = array_merge($output_data, $data);
}
else {
$output_data += $data;
}
}
return $output_data;
}