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.
Problem/Motivation
The serialized representation of a book node doesn't contain the book metadata.
This means on deserializing the book information is lost.
Proposed resolution
Add a normlizer for book data.
Remaining tasks
Patch, test, review
User interface changes
None
API changes
None
Data model changes
New information in serialized representation of a book node.
Comment | File | Size | Author |
---|---|---|---|
#13 | 2698785-interdiff-9-13.txt | 18.48 KB | jan.stoeckler |
#13 | 2698785-13.patch | 23.12 KB | jan.stoeckler |
#9 | 2698785-interdiff-7-9.txt | 11.14 KB | jan.stoeckler |
#9 | 2698785-9.patch | 10.88 KB | jan.stoeckler |
#7 | 2698785-interdiff-5-7.txt | 483 bytes | jan.stoeckler |
Comments
Comment #3
larowlanThere are tests and a normalizer in entity pilot module that can be borrowed here
Comment #4
jan.stoecklerI'll take a stab at this if it's alright.
Comment #5
jan.stoecklerThis is basically a copy & paste effort, as suggested. I'll be happy to add to that if needed.
Comment #7
jan.stoecklerOops.
Comment #8
tstoecklerYay, thanks for this! I must admit that I don't know too much about Book module, so this is a lot of nitpicks and a couple of general remarks, although a couple of things are specific to Rest, albeit not Book.
Here, and elsewhere: This is no longer required, and will bug anyone running PHPCS on core. Please remove.
This is pretty nitpicky, but this doesn't actually create a service modifier, it is one. How about:
We're adding a service, so we should instead implement
ServiceProviderInterface
. That has aregister()
method, instead ofalter()
but it works the same way. It just fits better semantically with what we're doing here.It's not clear to me from reading the patch why this is needed. Can we at least add some docs?
Again very nitpicky, but:
hal.module -> HAL module
active -> installed
Here, and elsewhere: Could be changed to use the new array syntax.
Yay, thank you so much for this!!! In my opinion every service priority should be documented explicitly, but we rarely do it. Thanks, this is great!
Too many newlines.
Let's use the EntityTypeManagerInterface instead.
For extra credit we can use
NodeInterface::class
now.The config factory is missing.
Because the config can be updated while this service persists, it's discouraged to actually store config values in a service instead of the config factory. In this particular the actual use-case that would be broken is probably a bit far-fetched, but I would still consider it a best practice to inject the config factory itself, instead of just the values.
In my opinion the fact that this variable is being used as a cache is not as interesting as what it actually contains. I would suggest naming it
$embedded_nodes
.Let's be nice to the extenders (TM) and use
static::
.I think it's strange to have a guard condition (the 1st if) and then wrap the rest of the code in another if. Either we should make all conditions part of the guard or just put all the conditions in the second if. Because there's another if-else inside there, I would lean towards the former. Also, the second if is formatted strangely.
$embedded_cache
is never actually populated inside of this if. That also means that the else-branch will never be reached. Given that I think it would be nice to add a unit test for this class.This looks similar to some code in
EntityReferenceItemTrait
. Does it make sense to add aEmbeddingNormalizerTrait
(or similar)?I realize this is copied from
EntityReferenceItemNormalizer
but I don't think our coding standards allow this.Per the above this code will never actually be reached, but it seems as though this should be wrapped in a
if (isset($embedded['lang']))
.This is a genuine question, I really don't know: Should we use the EntityResolver for this?
Is setting the
bid
tonew
something we should handle in the book denormalization?It's a bit unfortunate that we don't use different IDs here for testing purposes.
Comment #9
jan.stoecklerI cannot address your questions, but tried to fix everything else. For some reason the modified test fails on my machine, but I cannot successfully debug it, so let's see what the testbot finds.
Comment #10
jan.stoecklerAnd, of course, I forgot to change the issue status. Sorry!
Comment #11
larowlanThe embedded links added to the hal output need reference a particular field.
As per #2577923: MenuLinkContent entities pointing to nodes are not deployable: LinkItem should have a "target_uuid" computed property we should also be adding something to serializer module (basically the bid/pid bits without the embedding).
This represents a hole in our serialization APIs. What we're doing here is effectively hijacking serializing of *all* nodes just for the sake of one module - book. If we need another module to operate on a different node-type (eg. in contrib), then it cannot live alongside this normalizer without extending from it.
I think we should instead look at injecting the event dispatcher into the existing ContentEntityNormalizer and dispatching an event in both normalize and denormalize methods and then add an event listener in the book module, that way other modules can interact with node normalizing.
I know book is doing the wrong thing (not declaring field definitions) and that is the source of the issue, but there are heaps of contrib modules that do the same thing.
And yes, I realise this is c/p from my code in EntityPilot but I can get away with it there, I don't think we can in core.
Thoughts?
Comment #12
larowlan#2577923: MenuLinkContent entities pointing to nodes are not deployable: LinkItem should have a "target_uuid" computed property adds a trait for the ERItem embedding stuff, will help here
Comment #13
jan.stoecklerI hadn't caught comment #12, so for now we're not using the proposed trait, but i'll be happy to implement it if the general direction of this patch is fine.
Comment #15
jan.stoecklerOn a related note, could https://drupal.org/node/2419825 be related to this issue in some way/would it make sense to leverage the work done there?
Comment #18
Anas_maw CreditAttribution: Anas_maw at Vardot commentedHey, any updates on this issue, serializing book still does not include book metadata.
Comment #24
larowlanIn retrospect, this is a feature request, not a bug
Comment #29
quietone CreditAttribution: quietone at PreviousNext commentedThis extension is being deprecated, see #3376070: [Meta] Tasks to deprecate Book module. It will be removed from core and moved to a contrib project, #3376101: [11.x] [Meta] Tasks to remove Book.
This is now Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.
This issue may be re-opened if it can be considered critical, If unsure, re-open the issue and ask in a comment.
Comment #30
quietone CreditAttribution: quietone at PreviousNext commentedUn-assigning per Assigning ownership of a Drupal core issue.