Problem/Motivation
Something is incomplete or out of date with the display of log entities. The edit form appears fine but the View tab is empty.
Steps to reproduce
I went to https://simplytest.me and created a sandbox with Entity Log 8.x-1.4. (I tried the beta but the configuration screen failed with an error.) Configure anything to record changes and check the "log to entities" checkbox. Make some changes to the configured entities. Go to the log entities list and click on any of the log entities. From the Edit form, click on the View tab.
Proposed resolution
There are two template files. I am pretty sure that the correct file name is entity-log.html.twig. The preprocess function in entity_log.page.inc is looking for something that doesn't exist. But that function doesn't seem to be necessary in any case. I changed the variable in the twig file from 'content' to 'children' and I'm seeing what I expected now.
Remaining tasks
Update the relevant code and files to match the original intent for displaying a log entity.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 3469282 before.png | 79.35 KB | csakiistvan |
| #6 | 3469282 after.png | 146.83 KB | csakiistvan |
Issue fork entity_log-3469282
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
sorabh.v6Working on it.
Comment #4
sorabh.v6Updated the code in the template file and its showing up now. Please review.
There's some existing code that I think is not useful and we can create a new issue to remove the unnecessary code.
Thanks
Comment #5
demeritcowboy commentedThis works for me.
(I'm a bit confused that the log entries don't show you the date/time of the log entry anywhere, but seems like a separate issue. It stores it in the entity_log table, but isn't visible on either view or edit.)
Comment #6
csakiistvanEnvironment
Prerequisites
ddev drush en entity_log -y/admin/config/system/entity-logenable Log in Entity Log entity and select at least one field (e.g. Title) to log for a content type such as Article.Steps
ddev drush cr/admin/structure/entity_log) and open any log entity.Expected results
Actual results
Before the fix the View tab was empty: the
entity_logtheme hook resolves to the template fileentity-log.html.twig(hyphen), but the real template shipped asentity_log.html.twig(underscore) and was never loaded, so only the placeholder comment<!-- Add you custom twig html here -->rendered. After the fix the View tab shows the logged fields, e.g. Field label "Title", Old field value "Cache redirect test node", New field value "Cache redirect test node (edit)".Note on MR !9
Renaming the template to
entity-log.html.twigis correct and required, but printing the whole render element with{{ children }}does not work on Drupal 11: that element still carries#theme: entity_log, so it re-themes itself and triggers a "Recursive rendering attempt aborted" warning, leaving the div empty. The underlying reason the originalcontentvariable was empty is thattemplate_preprocess_entity_log()lives inentity_log.page.inc, whichentity_log_theme()never registers, so the preprocess never runs. The working template iterates the field items directly:<div{{ attributes.addClass('entity_log') }}> {% for key, item in children %} {% if key|first != '#' %} {{- item -}} {% endif %} {% endfor %} </div>Testing produced with the assistance of an LLM.
Comment #7
csakiistvanComment #8
csakiistvanComment #9
csakiistvanchange version to the latest one, the previous test can reproduce it on 1.4 and 1.5 too