function datalayer_add in dataLayer 8
Same name and namespace in other branches
- 7 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.
4 calls to datalayer_add()
- DataLayerKernelTest::testDataLayerAddDoesNotOverwriteByDefault in tests/
src/ Kernel/ DataLayerKernelTest.php - Test DataLayer Add Does Not Overwrite By Default.
- DataLayerKernelTest::testDataLayerAddWillAddData in tests/
src/ Kernel/ DataLayerKernelTest.php - Test DataLayer Add Will Add Data.
- DataLayerKernelTest::testDataLayerAddWillOverwriteWithFlag in tests/
src/ Kernel/ DataLayerKernelTest.php - Test DataLayer Add Will Overwrite With Flag.
- datalayer_get_data_from_page in ./
datalayer.module - Add data for output.
1 string reference to 'datalayer_add'
- DataLayerKernelTest::setupEmptyDataLayer in tests/
src/ Kernel/ DataLayerKernelTest.php - Setup empty datalayer.
File
- ./
datalayer.module, line 386 - Client-side data space.
Code
function datalayer_add(array $data = [], $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;
}