Skip to content
Snippets Groups Projects

Add langcode constructor parameter to LayoutParagraphsLayout so that entity translations are shown correctly.

4 unresolved threads

Closes #3305070

Merge request reports

Members who can merge are allowed to add commits.
Approval is optional
Code Quality is loading
Test summary results are being parsed
Ready to merge by members who can write to the target branch.
  • The source branch is 4 commits behind the target branch.
  • 1 commit will be added to 2.0.x.
  • Source branch will not be deleted.

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
270 288 $items = [];
271 289 foreach ($this->paragraphsReferenceField as $field_item) {
272 290 if ($field_item->entity) {
273 $items[] = $field_item->entity;
291 $items[] = $this->langcode ? $field_item->entity->getTranslation($this->langcode) : $field_item->entity;
  • Joachim Noreiko added 1 commit

    added 1 commit

    Compare with previous version

  • Jordan Graham
    Jordan Graham @COBadger started a thread on an outdated change in commit 9947ca6d
  • 270 288 $items = [];
    271 289 foreach ($this->paragraphsReferenceField as $field_item) {
    272 290 if ($field_item->entity) {
    273 $items[] = $field_item->entity;
    291 $items[] = $this->langcode ? $field_item->entity->getTranslation($this->langcode) : $field_item->entity;
    • I agree that we need to test whether a translation exists or not. This is the logic that worked for me (instead of $items[] = $this->langcode ? $field_item->entity->getTranslation($this->langcode) : $field_item->entity;):

              if ($field_item->entity->hasTranslation($this->langcode)) {
                $items[] = $field_item->entity->getTranslation($this->langcode);
              } else {
                $items[] = $field_item->entity;
              }

      When I tested the suggested change by @jleehr and edited a translated version of the node, a new paragraph created in the original language did not appear in the layout editor. With the above logic the new paragraph does appear and saves properly.

      Edited by Jordan Graham
    • Having tested my approach above and discussed it with colleagues I retract my suggestion.

      I have tested the MR without the suggestion from @jleehr and found that if I add a paragraph in the original language and edit a translation of that node, the layout editor fails to open and Drupal logs a php error saying InvalidArgumentException: Invalid translation language (es) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (line 874 of /app/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php).

      With the suggestion from @jleehr the layout editor functions properly and no php error is logged.

    • Jordan Graham changed this line in version 3 of the diff

      changed this line in version 3 of the diff

    • Please register or sign in to reply
  • Jordan Graham added 1 commit

    added 1 commit

    • 9a42a058 - Tested with this suggestion and it resolved an error that I experienced using...

    Compare with previous version

  • Jan Leehr
    Jan Leehr @jleehr started a thread on the diff
  • 270 288 $items = [];
    271 289 foreach ($this->paragraphsReferenceField as $field_item) {
    272 290 if ($field_item->entity) {
    273 $items[] = $field_item->entity;
    291 /** @var ContentEntityInterface $entity */
    • Nit: Should have the complete namespace or a use statement.

      Suggested change
      303 /** @var ContentEntityInterface $entity */
      303 /** @var Drupal\Core\Entity\ContentEntityInterface $entity */
    • Please register or sign in to reply
  • ytsurk added 1 commit

    added 1 commit

    • 301b105d - Makes sure original content is shown when creating a new translation

    Compare with previous version

  • ytsurk added 2 commits

    added 2 commits

    Compare with previous version

  • Seth Hill added 32 commits

    added 32 commits

    Compare with previous version

  • 283 300 $items = [];
    284 301 foreach ($this->paragraphsReferenceField as $field_item) {
    285 302 if ($field_item->entity) {
    286 $items[] = $field_item->entity;
    303 /** @var ContentEntityInterface $entity */
    304 $entity = $field_item->entity;
    305 if ($this->langcode) {
    306 $entity = $entity->hasTranslation($this->langcode) ? $entity->getTranslation($this->langcode) : $entity->addTranslation($this->langcode, $entity->toArray());
    Please register or sign in to reply
    Loading