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?

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.

| improve this answer | |
  • Thank you! This looks like what I needed. I'll be looking into it but may have more questions haha really appreciate it though! – Joe Spinelli Jan 16 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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