0

Whenever I am creating or editing a node, in the preview mode I see these errors.

enter image description here

This is the code I am using.

/**
 * Implements hook_preprocess_html().
 */
function campaigns2019_preprocess_html(&$variables) {
  if (isset($variables['node_type']) && $variables['node_type'] === 'landing_page') {
    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node->field_dark_theme->value) {
      echo("<script>console.log('here');</script>");
      $variables['attributes']['data-theme'] = 'dark';
    }
  }
}

The dark theme does not show up in preview mode though. However, if I ignore the errors and create my page, the dark theme works and everything seems to be displayed correctly. When is template_preprocess_html() called? Where in Drupal is it called?

1 Answer 1

0

The error is about accessing field_dark_theme from an un-existing node instance. The proper way of loading the node during preview is explained here.

On the other hand, welcome to the wonderful world of PHP for debugging properly (on Drupal), please check this post and this documentation entry check your proper IDE/stack on how to setup debugging tools.

1
  • Thank you! This looks like what I needed. I'll be looking into it but may have more questions haha really appreciate it though! Jan 16, 2020 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.