Not able to load translated paragraph of node using jsonapi

Created on 22 March 2023, over 1 year ago
Updated 6 April 2023, over 1 year ago

Hi All,

I am trying to load translation of paragraph with jsonapi.
Its simple jsonapi/content_type , for everything else its working fine
but I have a nested paragraph for which its not loading translated Content.

I have an idea that jsonapi don't support transport entirely but except for this for our project its giving us proper translations.

If anyone have any idea please suggest.

Thanks in Advance.

๐Ÿ› Bug report
Status

Closed: duplicate

Version

9.5

Component
Language systemย  โ†’

Last updated about 20 hours ago

  • Maintained by
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany @sun
Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia ajay547

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

Comments & Activities

  • Issue created by @ajay547
  • Status changed to Postponed: needs info over 1 year ago
  • Drupal.org is no longer accepting bug reports for Drupal 8. Drupal 8 reached end-of-life on November 2, 2021.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia larowlan ๐Ÿ‡ฆ๐Ÿ‡บ๐Ÿ.au GMT+10
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ajay547

    Hi @cilefen & larowlan

    I have update my site to Drupal core 9.5.7
    still I am facing the translation issue.
    The nested paragraphs are allways loading in default language (en) and this is breaking my site's translation.
    Any input or workaround here will be highly appreciated I am blocked on this.

    Thanks in Advance

  • I am glad you upgraded!

    Please can you add to the issue summary the specific steps to reproduce the issue so the maintainers can have a look into this?

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ajay547

    Hi cilefen,

    Sure here is the summary for my issue.
    I have a content type basic_page. It has one field of paragraph say A. Now one field of paragraph lets say field_B is again referencing to various paragraphs fields. Now If I am creating a node and in field_A selecting a paragraph field lets say field_C which has further paragraph reference in one of its field, then it is giving me translation issue.
    This is happening only if I select field_B, for creaing my node, in case I am not referencing field B and referencing some other fields, then it is working fine. Now I am using JSONAPI to pull reference for the paragraph fields value through include parameter in JSONAPI.

    Thanks in Adavance.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ajay547

    I feel something is wrong in this piece of code

    protected function resolveIncludeTree(array $include_tree, Data $data, Data $includes = NULL) {
    $includes = is_null($includes) ? new IncludedData([]) : $includes;
    foreach ($include_tree as $field_name => $children) {
    $references = [];
    foreach ($data as $resource_object) {
    // Some objects in the collection may be LabelOnlyResourceObjects or
    // EntityAccessDeniedHttpException objects.
    assert($resource_object instanceof ResourceIdentifierInterface);
    if ($resource_object instanceof LabelOnlyResourceObject) {
    $message = "The current user is not allowed to view this relationship.";
    $exception = new EntityAccessDeniedHttpException($resource_object->getEntity(), AccessResult::forbidden("The user only has authorization for the 'view label' operation."), '', $message, $field_name);
    $includes = IncludedData::merge($includes, new IncludedData([$exception]));
    continue;
    }
    elseif (!$resource_object instanceof ResourceObject) {
    continue;
    }
    $public_field_name = $resource_object->getResourceType()->getPublicName($field_name);
    // Not all entities in $entity_collection will be of the same bundle and
    // may not have all of the same fields. Therefore, calling
    // $resource_object->get($a_missing_field_name) will result in an
    // exception.
    if (!$resource_object->hasField($public_field_name)) {
    continue;
    }
    $field_list = $resource_object->getField($public_field_name);
    // Config entities don't have real fields and can't have relationships.
    if (!$field_list instanceof FieldItemListInterface) {
    continue;
    }
    $field_access = $field_list->access('view', NULL, TRUE);
    if (!$field_access->isAllowed()) {
    $message = 'The current user is not allowed to view this relationship.';
    $exception = new EntityAccessDeniedHttpException($field_list->getEntity(), $field_access, '', $message, $public_field_name);
    $includes = IncludedData::merge($includes, new IncludedData([$exception]));
    continue;
    }
    $target_type = $field_list->getFieldDefinition()->getFieldStorageDefinition()->getSetting('target_type');
    assert(!empty($target_type));
    foreach ($field_list as $field_item) {
    assert($field_item instanceof EntityReferenceItem);
    $references[$target_type][] = $field_item->get($field_item::mainPropertyName())->getValue();
    }
    }
    foreach ($references as $target_type => $ids) {
    $entity_storage = $this->entityTypeManager->getStorage($target_type);
    $targeted_entities = $entity_storage->loadMultiple(array_unique($ids));
    $access_checked_entities = array_map(function (EntityInterface $entity) {

    return $this->entityAccessChecker->getAccessCheckedResourceObject($entity);
    }, $targeted_entities);
    $targeted_collection = new IncludedData(array_filter($access_checked_entities, function (ResourceIdentifierInterface $resource_object) {
    return !$resource_object->getResourceType()->isInternal();
    }));
    $includes = static::resolveIncludeTree($children, $targeted_collection, IncludedData::merge($includes, $targeted_collection));
    }
    }
    return $includes;
    }

    Here I am not able use $entity_storage->loadMultiple(array_unique($ids)) along with translation.

    just for reference this is code from this file
    web/core/modules/jsonapi/src/IncludeResolver.php

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ajay547

    Hi cilefen,

    Thanks for your time and help, I found some help in this link.
    https://www.drupal.org/project/drupal/issues/3088239 ๐Ÿ› Revisions on relations are not loaded correctly resulting in wrong data in includes Needs work

    Updating here as this could be helpfull for some one.

    TIll Drupal 9.3 only revisions supported are file and node, after 9.3 update Drupal started support for paragraph revisions, so you need to bring your core above 9.3 and also you need to handle the permission (allow view revisions and allow view media revisions).

    Thanks

  • Does this issue duplicate ๐Ÿ› Revisions on relations are not loaded correctly resulting in wrong data in includes Needs work , or, should this issue be closed as โ€œworks as designedโ€?

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia ajay547

    Hi Cilefen,
    Yes correct this issue is duplicate of this.

    Team this issue is duplicate of
    https://www.drupal.org/project/drupal/issues/3088239 ๐Ÿ› Revisions on relations are not loaded correctly resulting in wrong data in includes Needs work
    just some additional points to remember here

    - Dont forget to update your Drupal core to atleast 9.3.0 in order to use this patch, because from 9.3.0 the core supposets revisions for paragraph and prior to that it supports only revision for node and media.
    - You will need to handle view all revisions permission and view all media revisions.

  • Status changed to Closed: duplicate over 1 year ago
Production build 0.71.5 2024