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
#2392845: Add a trait to standardize handling of computed item lists will add a ComputedItemListTrait
which takes care of all the entry points of a computed field item list. The current implementation of the computed path field has at least one open (and one fixed) bug:
#2905524: The count() method used on PathFieldItemList behaves differently if isEmpty() has been called.
#2908674: When using get() method directly on PathItem the alias is not loaded
Proposed resolution
Use it in PathFieldItemList
in order to handle all the possible cases of accessing the computed value.
Remaining tasks
Review.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.
Comment | File | Size | Author |
---|---|---|---|
#12 | interdiff.txt | 818 bytes | amateescu |
#12 | 2916300-12.patch | 7.12 KB | amateescu |
#9 | interdiff.txt | 1.59 KB | amateescu |
#9 | 2916300-9.patch | 7.14 KB | amateescu |
#9 | 2916300-9-combined.patch | 19.92 KB | amateescu |
Comments
Comment #2
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedLet's try this.
Comment #4
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThis should fix the failing REST tests. Since the 'computed' logic has been moved to the item list class, the field item class can now behave like a regular field!
However, the path tests will start failing just like in #2905524-12: The count() method used on PathFieldItemList behaves differently if isEmpty() has been called., because this change also fixes the bug reported over there, so it gets into the same problem with the path widget.
I'm really not sure if the fixes over there are correct or not, so I'll leave it to @Berdir to take a look whenever he can.
Comment #6
jibranSo this is not a BC break?
Comment #7
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI don't think so, given that the general behavior of the field is not altered in any way.
Comment #8
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedOk, I figured out how we can proceed here. We can take the 'langcode' property into account in
\Drupal\path\Plugin\Field\FieldType\PathItem::isEmpty()
, which effectively makes this field "never empty", which is exactly how it behaves in HEAD.This keeps the
count($node_with_no_path->get('path')) == 1
behavior, even though I think it's wrong, but we can punt on #2905524: The count() method used on PathFieldItemList behaves differently if isEmpty() has been called. to fix that.Comment #9
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented#2909183: Add path alias (PathItem) field PATCH test coverage was committed today and added some ugly code to the
PathItem
class, so let's reroll this patch on top of #2392845-133: Add a trait to standardize handling of computed item lists and remove that ugly code as well.Seems to be working fine still based on a quick local testing.
Comment #10
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedA slight change in the title is needed as well.
Comment #11
Wim LeersHurray!
Quoting myself from #2909183-20: Add path alias (PathItem) field PATCH test coverage (you left a comment at -19 pointing to #9 here):
Comment #12
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe parent issue moved the trait back to the typed data level so we also need a small update here.
Comment #13
Wim LeersThis blocks #2824851: EntityResource::patch() makes an incorrect assumption about entity keys, hence results in incorrect behavior, which is major.
Comment #14
Wim LeersThis is blocked on #2392845: Add a trait to standardize handling of computed item lists.
Comment #15
BerdirComment #16
BerdirComment #17
Wim LeersQueued tests for #12, but given that #9 already was green, I think it's okay to already RTBC this.
Comment #19
Wim LeersMust've been a random DrupalCI failure, because #12 is definitely green, despite this being marked NW. Back to RTBC.
Comment #22
larowlanCommitted as dbfe03c and pushed to 8.5.x.
Cherry-picked as ccc4d9c and pushed to 8.4.x.
Comment #23
Wim LeersThis unblocked:
Comment #25
karenann CreditAttribution: karenann as a volunteer commentedUpon updating from 8.4.2 to 8.4.4, I found that nodes created via REST were no longer being created with the defined alias pattern.
To elaborate, I have an alias pattern so that nodes created of the type "event" have the alias pattern of "/event/[node:title]".
After the update, nodes created via REST were being created as "/node/nid", the default method.
Reversing this commit to 8.4.x tree causes my nodes created via REST to be created with the correct URL alias pattern.
Comment #26
Berdir@karenan: That's most likely a problem in combination with pathauto module because the autoloading conflicts with the customized flag it adds there.
If you also add pathauto => FALSE inside path then it probably works again.
Comment #27
karenann CreditAttribution: karenann as a volunteer commentedUnfortunately, I can't wrap my brain around how to implement the suggestion @berdir has made. I will gladly accept any additional guidance.
In any event, I appreciate the advice! Thanks!
Comment #28
BerdirMaybe I misunderstood? You want to have the default generated alias and don't explicitly send an alias?
Either way, I'd recommend you open a bug report in pathauto, I'll try to have a look at it there. A test case or so would be extremely useful in helping to debug and fix this and makes it much more likely that I'll find time to look into it.