Handle entity revision for Render and Loader

Created on 13 December 2021, almost 3 years ago
Updated 13 March 2023, over 1 year ago

Problem/Motivation

When calling both bamboo_render_field or bamboo_load_entity without IDs parameters, those are guessed from the CurrentRouteMatch. But, when we want to load/render Revision Entity/Field, it will by default guess the $entity_type from CurrentRouteMatch.

Our problem, when accessing a node revision page (node/1/revisions/2/view), we want both bamboo_render_field('title', 'node') or bamboo_load_entity('node') to load the revision 2 and not the Node ID 1.

Steps to reproduce

1. Update the revision template of any Node/Taxonomy that is revisionable

node.html.twig

2. Use {{ bamboo_load_entity('node').title.value }} in that template and print values

3. Create sample data as follow:

  • Create a node article with title "Article 1"
  • Edit the previous node article, check the "create revision" and rename the node "Revised Article 1"
  • Create a node article with title "Article 2"

With this sample data you will have the following IDs:

- Article 1 = Node ID 1 (nid 1) with 2 revisions IDs (1, 2)
- Article 2 = Node ID 2 (nid 2) with 1 revision ID (3)

3. Browser to the page using node.html.twig

- node/1/revisions/1/view will display Article 1
- node/1/revisions/2/view will display Article 1
- node/1/revisions/3/view will display Article 1
- node/2/revisions/1/view will display Article 2
- node/2/revisions/2/view will display Article 2
- node/2/revisions/3/view will display Article 2

Instead we want

- node/1/revisions/1/view will display Article 1
- node/1/revisions/2/view will display Revised Article 1
- node/1/revisions/3/view will display Article 2
- node/2/revisions/1/view will display Article 1
- node/2/revisions/2/view will display Revised Article 1
- node/2/revisions/3/view will display Article 2

Proposed resolution

We have no way to fix this behavior inside bamboo_load_entity.

We have to create a new function bamboo_load_entity_revision which is able to load only revision of given ID or guessed from URL (CurrentRouteMatch).

Remaining tasks

  • Code the new bamboo_load_entity_revision
  • Add tests about bamboo_load_entity_revision

User interface changes

None

API changes

  • New Twig function bamboo_load_entity_revision

Data model changes

None

🐛 Bug report
Status

Fixed

Component

Code

Created by

🇨🇭Switzerland dibix

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024