0

I am using hook_node_presave() to render my node and then save the output to a field field_node_cache. However, when I do this, the renderer uses the admin theme, whereas I would like to use the site's main theme.

Is there a way to force it to use the site's main theme without disabling the admin theme?

function MYMODULE_node_presave(NodeInterface $entity) {
  switch ($entity->getType()) {
    case 'MY_CONTENT_TYPE':
      $render_controller = \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId());
      $render_output = $render_controller->view($entity, 'MY_VIEW_MODE', 'ja');
      $html = \Drupal::service('renderer')->renderPlain($render_output);

      $entity->set('field_text_main_display', $html);
      $entity->field_node_cache->format = 'MY_FORMAT';
    break;
  }
}
0

One way to work around this is to go to /admin/appearance and uncheck Use the administration theme when editing or creating content.

Alternately, you can create a separate user account that does not have permission View the administration theme and use that account to create content.

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.