Unable to render paragraph as entity field with Drupal renderer

Created on 23 July 2024, 4 months ago
Updated 24 July 2024, 4 months ago

Problem/Motivation

Hello!

I've a custom entity. This entity has a paragraph field, but when I try to render the entity, the paragraph fields are not displayed.

$view_builder = Drupal::entityTypeManager()->getViewBuilder('my_entity');
$pre_render = $view_builder->view($entity);
$html = Drupal::service('renderer')->render($pre_render);

After that code the $html not contains the paragraph field.
How can I fix that?
Thank you!

💬 Support request
Status

Closed: works as designed

Version

1.17

Component

Code

Created by

🇭🇺Hungary kecsot Hungary

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kecsot
  • 🇭🇺Hungary kecsot Hungary
  • 🇭🇺Hungary kecsot Hungary

    looks like permission issue. it works with administrator role but not with anonymous

  • 🇭🇺Hungary kecsot Hungary

    ParagraphAccessControlHandler::checkAccess

        if ($paragraph->getParentEntity() != NULL) {
          // Delete permission on the paragraph, should just depend on 'update'
          // access permissions on the parent.
          $operation = ($operation == 'delete') ? 'update' : $operation;
          // Library items have no support for parent entity access checking.
          if ($paragraph->getParentEntity()->getEntityTypeId() != 'paragraphs_library_item') {
            $parent_access = $paragraph->getParentEntity()->access($operation, $account, TRUE);
            $access_result = $access_result->andIf($parent_access);
          }
        }

    The parentEntity->access was only "neutral". The anonymous user not had access to rendered entity.

    Works as designed. Sorry :)

  • Status changed to Closed: works as designed 4 months ago
  • 🇭🇺Hungary kecsot Hungary
Production build 0.71.5 2024