Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Testing the json result for a book I see no child data which is imho necessary to make it useful drill down a book.
In HTML view the children are done by the class BookOutline {
which is something different.
I expected the direct children when asking for json on ie http://drupal.d8/node/1
What do I miss?
Comment | File | Size | Author |
---|---|---|---|
#25 | hal-add-book-support-2291811-25.patch | 8.73 KB | smulvih2 |
#23 | hal-add-book-support-2291811-23.patch | 8.65 KB | smulvih2 |
Issue fork hal-2291811
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 #1
clemens.tolboomI consider this now a HAL problem.
Using https://github.com/mikekelly/hal-browser neither an Article as top level book or a book page shows child pages to their _links or _embed
I myself would expect the child pages in _embed
Maybe this should be a view?
Comment #2
clemens.tolboomComment #3
Wim LeersIn
template_preprocess_book_navigation()
:I think the root cause of the problem here is that the book module does not embed this metadata in anyway in the entity. It's stored outside of the entity, and it is only presented by manipulating render arrays when viewing entities. So I don't think
hal
module could do this even if it wanted to.Comment #4
dawehnerWell, yeah the book module would need to integrate into HAL I would say. I think there is no other way without breaking APIs.
Comment #15
quietone CreditAttribution: quietone at PreviousNext commentedAsked about this in #bugsmash, larowlan replied that this does belong in HAL project in contrib and it is a feature request.
Making those changes now.
Comment #18
smulvih2I am using the drupal/default_content_deploy module for content deployment, which uses drupal/hal for normalizing the content into JSON files. I was running into the same issue where the book data was not being included in the output JSON files.
The issue appears to be how the book structure is attached to the node, it is not a field but just a simple array. MR#3 adds a book
normalizer
anddenormalizer
class to export/import the book structure with dependencies (_embedded).I had some trouble merging the book
_embedded
array into the main_embedded
array, so I have included the book dependencies within the book array. I had to modify the ContentEntityNormalizer::denormalize() method to account for this.Setting this ticket to Needs review to get some eyes on it, but this change will probably require a test, and maybe some dependency injection work.
Note - if using drupal/default_content_deploy, patch is needed (in related ticket).
Comment #19
smulvih2Comment #20
smulvih2Had to rebase the MR branch but looks good now.
Comment #21
smulvih2Comment #22
smulvih2Comment #23
smulvih2MR is against the 1.0.x branch and I can't seem to change that, but this branch seems to be aligned with the 2.0.1 release. Adding patch here for 1.0.3 release (1.x branch).
Comment #25
smulvih2Oops, forgot to account for when the book module is not enabled. Added a check before calling the
book.manager
service.Comment #26
smulvih2Ok tests are passing now on 1.x-dev branch for D9. Added this fix to the MR for 2.x-dev.
Comment #27
larowlanThis should be doable without needing to add special cases to the content entity normalizer.
Entity pilot module also relied on hal, and it had a single stand alone class for books - https://git.drupalcode.org/project/entity_pilot/-/blob/8.x-1.x/src/Norma...
It also had a test, we should be able to borrow from that too https://git.drupalcode.org/project/entity_pilot/-/blob/8.x-1.x/tests/src...
Comment #28
smulvih2@larowlan thanks for the feedback and links! Will take a look at removing the changes to the ContentEntityNormalizer as you suggest and including tests as well.