Skip to content

Commit

Permalink
#10 add poor man's debugging function
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Sep 3, 2019
1 parent eec64cb commit 1b71191
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions csis_helpers.module
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ use Drupal\group\Entity\GroupContent;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;

/**
* Disable in production!
*/
$DEBUG = true;

/**
* Poor man's debugger
* See https://stackify.com/how-to-log-to-console-in-php/
*/
function console_log($output, $with_script_tags = true)
{
if ($DEBUG) {
$js_code = 'console.log([CSIS_HELPERS_MODULE > ]' . json_encode($output, JSON_HEX_TAG) . ');';
if ($with_script_tags) {
$js_code = '<script>' . $js_code . '</script>';
}
echo $js_code;
}
}

function csis_helpers_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode)
{
$type = $entity->bundle();
Expand All @@ -21,7 +41,7 @@ function csis_helpers_node_view(array &$build, EntityInterface $entity, EntityVi
$build['#attached']['library'][] = 'csis_helpers/seamless';
$build['#attached']['library'][] = 'csis_helpers/update_step_relations';
$build['#attached']['library'][] = 'csis_helpers/iframe_connector';

switch ($type) {
case 'gl_step':
$build['#attached']['drupalSettings']['csisHelpers']['studyInfo'] = $entityInfo;
Expand All @@ -37,7 +57,7 @@ function csis_helpers_node_view(array &$build, EntityInterface $entity, EntityVi
//default:$build['#attached']['drupalSettings']['csisHelpers']['studyInfo'] = $entityInfo;
}
} else {
// DEBUG LOG!
console_log(var_dump($entity));
}
}

Expand Down

0 comments on commit 1b71191

Please sign in to comment.