Problem/Motivation
Please guide me what changes I need to do for make machine name working for content entity.
Currently in Drupal 8, a 'machine_name' widget is available only on primary identifiers of config entities, as content entities were expected to use serial entity identifiers only.
Some specific content entity types, however, are bordering to configuration and are therefore better identified by a string. Use cases include Core's new Workspace, Entityqueue's EntitySubqueue, FillPDF's FillPDF forms and the OP's contrib PET entity types.
This constitutes a regression from D7 where 'machine_name' fields were available as entity identifiers.
Proposed resolution
- Create a machine_name widget
- Allow 'string' type primary identifiers to specify the 'machine_name' widget in a content entity type's BaseFieldDefinition.
- Switch Core's Workspace entity to using a 'machine_name' widget on its 'string'-type id field replacing the current, ugly workaround.
Remaining tasks
Respond to #80
Fix the test failure
Review the CR
Review
User interface changes
Screeenshots in #2685749-114: Add a 'machine_name' widget for string field types with a UniqueField constraint from the patch in the same comment.
API changes
- none -
Data model changes
- none -
Original issue
I'm trying to port PET module, it uses custom entity to manage mail templates.
It has a machine name field, which I'm not able to make in Drupal 8. I checked code of Drupal 8 core, it uses machine name field for config type entities only, I did same way but it does not behave like machine name.
Please guide me what changes I need to do for make machine name working for content entity. Also let me know if this is an issue in core, I think the way fields are rendered in content entity might be the reason.
Current code can be seen here http://cgit.drupalcode.org/pet/tree/.
Comment | File | Size | Author |
---|---|---|---|
#131 | machine-name-widget-2685749-130.patch | 33.71 KB | a.dmitriiev |
#129 | machine-name-widget-2685749-129.patch | 33.72 KB | a.dmitriiev |
#128 | reroll_diff_116_128.txt | 5.19 KB | a.dmitriiev |
#128 | machine-name-widget-2685749-128.patch | 33.69 KB | a.dmitriiev |
#127 | drupal-9-5x-machine-name-widget-2685749-127.patch | 14.15 KB | tgoeg |
Issue fork drupal-2685749
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
swentel CreditAttribution: swentel as a volunteer commentedWhy do you need a machine name for a content entity ? You already have the an id and uuid ?
Comment #3
Sharique CreditAttribution: Sharique as a volunteer commented@swentel, it was there in D7 version, so want to keep that as it is. Can you tell me why machine name field is not working for content entity type?
I'm also thinking about dropping machine name field if not able to make it work is correctly.
Comment #4
swentel CreditAttribution: swentel as a volunteer commentedWell, most content entities don't have machine name field as most of them use a serial field and a uuid. That's already unique enough to be fair.
Comment #5
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThe entity_subqueue content entity type from the Entityqueue module also needs a 'machine name' field widget, so I think it's worth giving this a try :)
Comment #9
timmillwoodLooks like we might need this for #2784921: Add Workspaces experimental module
Comment #10
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedHere's an initial WIP patch which shows the complexity of this widget. And there are two separate issues that need to be fixed as well, as can be seen in the first two hunks from the patch.
Not sending this patch to the testbot because it's useless at the moment.
Comment #11
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI finally managed to get this working. It was a lot trickier than I expected but I'm pretty happy with its behavior now and we have complete test coverage as well :)
Comment #12
timmillwoodLooks very awesome!
I can imagine it was tricky, but it's quite an elegant solution.
Small nitpick which can be fixed on commit, if it's an issue at all:
I wouldn't usually expect a blank line here.
Comment #13
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedOh, I always leave a blank line in the constructor between the parent call and local variable assignments, I like the code to have enough "breathing room" :)
Comment #15
larowlanI think this should be
no ui
. Pretty sure the UX/product team won't want to present 'regex' to users. Given we're going to use it on base fields for workspaces - I think that would be fine. @Sharique - can you confirm that would suit PET module too?Does this need to provide a config dependency on the field it references?
Is there a test for this?
I really think this should be its own Field Type that has a constraint to validate unique. We're validating unique in the form layer, but not for things like REST.
Comment #16
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThanks @larowlan for a great review! I've started to work on your points and I'll post a detailed reply tomorrow.
Comment #17
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedOk, here it is :)
Re #15:
1. Totally agreed there, it's exactly what I did initially only to find out that the "no ui" concept does not exist for widgets and formatters, only for field types. So we can do the next best thing and use
isApplicable()
to make this widget available only to entity ID fields. This is actually the 99% use case and it satisfies all the modules that need this widget so far: Workspaces, Entityqueue and the PET module from the IS.2. It doesn't need to declare a config dependency because the source field has to be configured in the form display if it wants to be available as a source and the entity form display config entity already depends on all its components (aka. configured fields).
3. There is now :)
4. Sadly, this can not really be its own field type because, for example, @alexpott asked in #2885469: Regression: manually setting the ID field for newly-created content entities is not possible anymore (public follow-up to SA-2017-002) to allow setting an entity ID explicitly only for string ID fields. And we also have an existing issue to deal with this in REST: #2870649: REST should respond with a 409 for a POST request to an existing entity
Since we're limiting this widget to be available only to ID fields, we're effectively blocked on #2885469: Regression: manually setting the ID field for newly-created content entities is not possible anymore (public follow-up to SA-2017-002) for now because the tests will fail without that patch.
Comment #18
Wim Leers@timmilwood pointed me to this issue while talking about #2885469: Regression: manually setting the ID field for newly-created content entities is not possible anymore (public follow-up to SA-2017-002). Adding issues linked from #17 to related issues to improve discoverability.
Comment #20
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented#2885469: Regression: manually setting the ID field for newly-created content entities is not possible anymore (public follow-up to SA-2017-002) is in, so we can unpostpone this one. It would allow us to clean up some form code in the workspaces module :)
Comment #21
timmillwoodThe patch from #17 looks good.
Comment #23
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedComment #24
alexpottI think the work around in #17 to not having
no ui
available looks good. Given it does not does do exactly what @larowlan asked for in #15 I'm going to ping @larowlan but I'm +1 on commit.Comment #25
larowlanI don't think this will work with IEF - so we need something less brittle here.
This is a reasonable compromise
Comment #26
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedRe #25.1: That's right and also easy to fix: we can just put all the info we need in the widget's form element.
Tested with IEF and everything works perfectly :)
Comment #27
larowlanI think this comment still stands?
Comment #28
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@larowlan, I answered that point in #17.4.
Comment #30
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedTestbot was acting up.
Comment #31
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedActually, now that the workspace module has been committed, we have the first use case for this widget in core!
The interdiff shows what kind of ugly code can be removed :)
Comment #33
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedA couple more tests needed to be updated.
Comment #34
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented#31 was a simple change to remove the current custom code from from Workspaces to use the new widget, which also brings an indirect level of test coverage on top of the existing dedicated one, so I think it's ok to move this back to RTBC.
Comment #36
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedRandom fail.
Comment #38
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedRerolled.
Comment #41
darvanenAs this is passing on 8.7 and it likely won't make it into 8.6, I think it should be RTBC as per #34
Comment #42
ndf CreditAttribution: ndf commented#15 and #27 are still open: larowlan asked for an additional unique FieldType.
The current patch adds a FieldWidget (in itself already an improvement).
Could we RTBC and then create a follow-up for the unique FieldType?
Comment #43
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@ndf, I replied to #15 and #27, see #17.4. And we're already RTBC :)
Comment #44
ndf CreditAttribution: ndf commented@amateescu Sorry I missed 17.4
Then RBTC from me too.
Comment #45
alexpottStill think this patch looks good. Realised though that the issue summary is out-of-date and there is no change record. Needs work for those things.
Comment #46
PanchoUpdated issue summary.
Comment #47
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThanks, @Pancho! Here's a CR too: https://www.drupal.org/node/3028311
Comment #48
PanchoFurther refined issue summary.
edit: Oops, now we have two change records. We might want to combine the best of both.
Comment #49
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@Pancho, oops indeed :) I added the usage example from your CR to the one linked in #47.
Comment #50
Panchoadded another followup task
Comment #51
PanchoThink this should actually be postponed to that other issue which is creating a whole new separate ‘machine_type’ field type.
Comment #52
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@Pancho, as far as I see, that issue introduces a 'machine_name' config data type, while this one is about providing a field widget for content entity types, so they're not related at all regarding their functionality.
Comment #53
Pancho@amateescu You're completely right, sorry. Remains RTBC.
Comment #54
dwwDo we need to enforce this? What if I want a 'machine_name' widget on some other kind of field? I might want all the same behavior of the machine name widget for giving machine names to some other kind of content on a site. E.g. I need my projects to have a machine name, even though they're nodes that officially have integer IDs. Why can't I define my own string field for this and reuse the 'machine name' widget?
Comment #55
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@dww, that was my attempt to resolve @larowlan's request from #15 (last paragraph), but now that I think about it again, maybe it's better to enforce that the field definition has a
UniqueField
constraint rather than being the entity identifier.Comment #56
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedA couple of self-review fixes :)
Comment #57
PanchoUpdated change record. I only added a sentence in the end, because the widget will still primarily be there for string-type identifiers.
This one now depends on #3027745: UniqueFieldConstraint doesn't work for entities with string IDs being committed first to ensure the machine_name really is unique, am I right? In that case, we should actually see a failing test here.
Comment #58
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedBetter title for the new approach in #55.
Comment #60
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedNot necessarily :) There are two use cases for this widget:
1) for the identifier field of an entity type with string IDs
2) for a string field with a UniqueField constraint, on an entity type with either integer or string IDs
The first case is what we're doing for the
workspace
entity type, and it works just fine. The second case is the "problematic" one, but only in the case where the entity type uses a string ID.So I'm not sure whether there's a hard dependency, that issue is a bug that needs to be fixed regardless of this new widget.
Comment #61
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThat issue was just committed, does anyone want to RTBC this one? :)
Comment #63
jhedstromThis looks good to me. Just some tiny nits below and then I think it's RTBC.
I'd hoped that machine names wouldn't always require node, so in digging I found that actually the `access content` permission is defined by the system module, so either just that module can be installed, or this comment can be updated.
Should new usages of deprecated functions be added?
Comment #64
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented@jhedstrom, thanks for the review!
Re #63:
1. Very good point, we can clean that up and just assign the
access content
permission to the test user because the system module is installed by default.2. Those functions are not really deprecated because they don't have any replacements. That problem will be fixed in #2367933: Move entity_get_(form_)display() to the entity display repository :)
Comment #65
jhedstromThis looks good to me.
Good to know! I'd always thought the recommended replacement in the deprecation notice was incomplete compared to the old functionality :)
Comment #66
PanchoAdded one more example. These are all borderline-configuration ContentEntityTypes.
Comment #68
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedFixed usages of
entity_get_form_display()
which is properly deprecated now.Comment #69
larowlanNote to other reviewers, this happens in the machine name element plugin (not in the widget)
We could also limit these by weight in the display here right?
I.e we're already filtering out items that aren't enabled, but could we also inspect their weight relative to the weight of this item?
if the entity is new, then why would it have a value in the database that would impact the query?
i.e if the entity is new, adding a
<>
against its ID won't return any results right? Because its not saved yet.I'm not convinced we need this change - can you elaborate on why it was needed?
Comment #70
andypostOnly nit
SortArray:class
Comment #72
joachim CreditAttribution: joachim commentedLooks good overall.
Just one small thing:
This is a detail that could do to be also mentioned in the class docs, for DX. Imagine a developer trying to figure out why this widget doesn't show in the UI.
Comment #73
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThanks everyone for the reviews :)
Re #69:
2. That's a good idea! Done and updated the test coverage to take this new behavior into account.
3. That change fixes a bug introduced in #3027745: UniqueFieldConstraint doesn't work for entities with string IDs, which didn't take into account that the
UniqueField
constraint could be set on the ID field itself. In that case, when adding a new entity with a string ID, the entity ID is set by the form (this doesn't happen for entities with integer IDs), so$entity->id()
will never be NULL, which essentially makes the query ignore other pre-existing entities which have the same ID as the newly created one.I've updated the comment and the code to make it more clear when we need to add that condition to the query.
#70: heh, fixed.
#72: good point, fixed as well.
Comment #74
andypostComment #75
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedSetting back to RTBC because all the reviews were addressed.
Comment #76
japerryThis is looking good. In prep for this getting into core, I've rolled a 2.x branch of the machine_name_widget module that contains most of this code.
Some of the core features like checking uniqueness isn't there, but the basic ability to add machine names is.
https://www.drupal.org/project/machine_name_widget/releases/8.x-2.0-alpha1
Comment #78
xjmThe 9.1.x tests failed: https://www.drupal.org/pift-ci-job/1672843
I requeued it to be sure, but this issue may need a different patch for 9.x. Thanks!
Comment #79
amateescu CreditAttribution: amateescu as a volunteer commentedFixed that :)
Comment #80
alexpottDoes this mean that you can break the form by re-ordering the fields in the UI? It looks like it. We prevent you from choosing an impossible source field but can you re-order the fields after doing this.
Should these changes have test coverage in \Drupal\KernelTests\Core\Validation\UniqueFieldConstraintTest?
Should we at least assert a 200?
Comment #81
vbory CreditAttribution: vbory commentedCan anybody explain why we use closure function in
MachineNameWidget
class?The
Drupal\Component\Serialization\PhpSerialize
can't serialize theMachineNameWidget
class, because we have closure function.Comment #82
Marcin Maruszewski CreditAttribution: Marcin Maruszewski at RatioWeb commentedI have the same issue as vbory said in #81. The issue occurs while I was trying to create a new entity_reference item via inline_entity_form (complex widget).
I copied patch from #79 but removed this Closure. I hope it's gonna work too.
Comment #83
Marcin Maruszewski CreditAttribution: Marcin Maruszewski at RatioWeb commentedSmall fix for #82
Comment #84
Neograph734Comment #85
Marcin Maruszewski CreditAttribution: Marcin Maruszewski at RatioWeb commentedApologies for last two, not working patches. I spend some time, check where this Closure is used and find some solution.
Like @bvory noticed a Closure can't be serialized. But as it's described in docs https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21... the "exists" parameter should be a callable.
For this issue, I have a workaround. We can create method witch always return false and set it as a callback. This solution is working for me, but I'm not sure is it a good solution. Maybe we just should check "MachineName::validateMachineName" does exist callback function is set and leave it empty in MachineNameWidget.
Comment #86
Neograph734I believe the issues @alexpott mentioned in #80 are still not resolved. So this still needs work?
Comment #88
gaurav_manerkar CreditAttribution: gaurav_manerkar as a volunteer commentedHello, Any update?
Comment #89
Daniel KulbeWorking properly.
Comment #91
Pasquallereroll
added option "Standalone" to the widget settings. see api.drupal.org
Comment #92
Pasquallereroll
Comment #94
weseze CreditAttribution: weseze as a volunteer commentedPatch from #92 wasn't working for us against 9.3.0.
So rerolled patch attached.
Comment #95
Akhildev.cs CreditAttribution: Akhildev.cs as a volunteer and at Zyxware Technologies commentedhi, I tried, the rerolled patch #94 is not working for me.
Comment #96
Supreetam09 CreditAttribution: Supreetam09 commentedPatch #73 for D8.9.x is partially working. Throwing issue "Serialization of Closure is not allowed in Serialize()" when trying to modify a custom content block having paragraph type entity reference field. Creating new patch here.
Note: This is for D8.9.x only.
Comment #97
Supreetam09 CreditAttribution: Supreetam09 commentedUpdating patch. Refer to above comment ^^.
Comment #98
charginghawk CreditAttribution: charginghawk at Pegasystems commentedRerolling the 94 patch for 9.3.0 / 9.3.x.
Comment #100
charginghawk CreditAttribution: charginghawk at Pegasystems commentedHm, rerolling the #92 patch for 9.3.0 / 9.3.x!
Comment #101
charginghawk CreditAttribution: charginghawk at Pegasystems commentedFixing this:
Comment #102
Supreetam09 CreditAttribution: Supreetam09 commentedAdding patch for specific 9.2.x Drupal core version following #101
Comment #103
Supreetam09 CreditAttribution: Supreetam09 commentedIgnore the above ^^ patch in #102 as I mistakenly did not add the untracked files.
Adding new patch for D9.2.x here.
Comment #104
volegerPHPCS is not happy
Comment #105
PasqualleThe field widget should have "Textfield size" option.
Comment #106
ankithashettyAddressed #105 in patch #101, please review.
Thanks!
Comment #107
jibranI think we need a usability review on this ticket before we tag it with "usability review" let's add all the screenshots for the widget and its setting to the IS.
Comment #109
sandeep_jangra CreditAttribution: sandeep_jangra at OpenSense Labs commentedI'm working on this.
Comment #111
nod_I'm guessing this won't make it to 9.x, so a D10 patch would be necessary (#106 seems to be applying well enough on 10.1)
In The D10 version
I think according to #3259716: Replace usages of static::class . '::methodName' to first-class callable syntax static::method(...) this should be:
uasort($components, SortArray::sortByWeightElement(...));
setting to NW for the screenshots at least
Comment #112
Akram KhanCreating patch for 10.1.x and address #111
Comment #113
Akram Khanattached reroll file
Comment #114
james.williams CreditAttribution: james.williams at ComputerMinds commentedPatch #112 (a re-roll of #106) omitted the new files that were being added in #106. (And the interdiff for it, posted in #113, therefore showed those files removed.)
Here's a replacement patch that includes the new files. This is a re-roll of #106, including the suggestion from #111 to use the new callable syntax. I include an interdiff of this vs #106. Drupal 9.5 sites may not support the callable syntax new to PHP 8.1, so I include a patch for D9.5.x too (without interdiff - I've just retained the previous
uasort($components, [SortArray::class, 'sortByWeightElement']);
line).I've also included some screenshots of the new widget settings (collapsed+expanded), and the widget itself in action (before+after clicking the 'edit' link). I trust those might be enough screenshots? Since this is new functionality, I presume we don't need screenshots of how it looked before the change? More can be made if needed of course!
Comment #116
james.williams CreditAttribution: james.williams at ComputerMinds commentedFixed the test failure which was due to case sensitivity. (To my surprise!)
I also spotted that the widget's
isApplicable()
relies on the options having been set when adding the constraint. I don't see anywhere documented that requires that; so I've replaced anisset()
for anarray_key_exists()
so that calls like->addConstraint('UniqueField')
will work rather than requiring an empty second parameter->addConstraint('UniqueField', [])
. (There are instances in core of other constraints being added without setting the options parameter, such as in\Drupal\Core\Entity\EntityType::__construct()
.)Comment #118
james.williams CreditAttribution: james.williams at ComputerMinds commentedPrevious test failure was for a hopefully unrelated Ckeditor5 test. Tests all passed on a retest!
Comment #120
smustgrave CreditAttribution: smustgrave at Mobomo commentedAccording to the issue summary #2905594: Missing entity validation constraint: don't allow new entities when there is an existing one with the same ID is still remaining. So my question is should this ticket be postponed on that one? Or is #2905594: Missing entity validation constraint: don't allow new entities when there is an existing one with the same ID not needed for this to move forward?
Comment #121
james.williams CreditAttribution: james.williams at ComputerMinds commentedThat issue talks about using a "duplicate ID" - if that's talking about a field with a unique value constraint, it could actually be solved by the work that has now been done here. All that would be needed (on top of this work) is for the constraint to be added to that field, I believe.
Or it's talking about using the entity ID field itself, rather than a field using a machine name constraint/field/widget. Which would be related, but I don't think blocks this issue at all. It might even still be able to make use of it in the same way - by simply adding the constraint to the appropriate entity ID field.
So I could be wrong, but I'm updating the IS based on that belief that it's a related issue, not a blocker to this one. Correct me if I am indeed wrong!
Comment #122
smustgrave CreditAttribution: smustgrave at Mobomo commentedThanks for updating that! This one may need more eyes but noticed the change record was written for D8 and this probably will only make it in 10.2. So if that could be updated.
Comment #123
james.williams CreditAttribution: james.williams at ComputerMinds commentedOk; updated the change record to now target 10.2.0.
10.2.x-dev isn’t an option for the issue metadata here though. I guess we just wait to get it into that or main or whatever becomes available?
Comment #124
smustgrave CreditAttribution: smustgrave at Mobomo commentedSo tested by enabling entity_test module and going to entity_test_string_id/structure/entity_test_string_id/form-display
Verifying the ID field can switch between textfield and machine_name.
Verified that regular Text(only) field doesn't get machine_widget.
Not sure how other to test this one. But lets get into committer eyes. May be easier to get into 10.2 early
Comment #125
quietone CreditAttribution: quietone at PreviousNext commentedThanks to everyone here for moving this 7 year old issue along!
I triaged this and updated the remaining tasks accordingly. Here are the details.
The issue summary states that there are no user interface changes but this is adding a new widget. And in #107, screenshots were asked for. I eventually found them in #144. @james.williams, thanks for making them. It really helps reviewers/committers if the screenshots are in the IS or a link to the comment so they can be found. Also, with a note saying which patch/MR version they were made with. (I just added it)
There were many questions raised in the reviews, that is good to see and read. However, #80 has not been answered. I have added that to the remaining tasks.
#124 says "Not sure how other to test this one. But lets get into committer eyes." Instead, before setting to RTBC ask in #contribute for first. An issue that is Reviewed & tested by the community ("RTBC") should not have any questions unanswered, it should be ready for commit.
I read the CR and made changes to use plain English. There should be no changes to the content but someone should check that. I am adding a review of the CR to the remaining tasks. The CR mentions the benefits to site builders but site builder' is not selected in the 'Impacts'. Should it be? The CR should also include a screenshot. These two look the most informative,
https://www.drupal.org/files/issues/2023-05-16/widget-settings-collapsed...
https://www.drupal.org/files/issues/2023-05-16/widget-settings-expanded.png
The latest patch is failing tests and is on 10.1x. This needs to be on 11.x with passing tests. Setting to NW.
I am updating credit, always a challenge on issues with > 100 comments.
A reminder to all that when making a patch, an interdiff or diff is needed. There are instructions for creating an interdiff. If you think a diff is not needed, add a comment stating why.
Comment #126
ankondrat4 CreditAttribution: ankondrat4 at Smile, Drupal Ukraine Community commentedHello.
You can try using this module https://www.drupal.org/project/machine_name_widget
Comment #127
tgoeg CreditAttribution: tgoeg commentedThe patch in #2685749-116: Add a 'machine_name' widget for string field types with a UniqueField constraint for Drupal 9.5 is broken.
It adds two unnecessary files
core/b/core/tests/Drupal/FunctionalJavascriptTests/Core/Field/Widget/MachineNameWidgetTest.php
core/b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/MachineNameWidget.php
They do not differ from the ones at the correct path, so I just removed them.
It should look like the one attached.
Comment #128
a.dmitriiev CreditAttribution: a.dmitriiev as a volunteer and at 1xINTERNET commentedRe-roll of the patch from 116 for 11.x. Fixing the testPublishWorkspace as well.
Comment #129
a.dmitriiev CreditAttribution: a.dmitriiev as a volunteer and at 1xINTERNET commentedFix failure of custom commands
Comment #130
AnybodyThanks @a.dmitriiev! :) Still 1 failing test left.
Could you perhaps use a MR to make reviews easier?
Comment #131
a.dmitriiev CreditAttribution: a.dmitriiev as a volunteer and at 1xINTERNET commentedHere is the patch the same as MR. I figured out the failing test: after changing machine name to client side only, the trailing replace char is also removed. I hope now the tests will pass.
Comment #133
a.dmitriiev CreditAttribution: a.dmitriiev as a volunteer and at 1xINTERNET commentedStill the same test fails. However, the expected string is exactly the same as widget produces in admin UI when checking the same thing manually.
Comment #134
leymannxComment #135
leymannxLooks like the machine name is wrong. When I add a new field anywhere in Drupal, naming it
Test value !0-9@
, the machine name gets auto-created asfield_test_value_0_9_
with an underscore (_
) at the end.Comment #136
leymannxWhich would be strange, though, as the machine name test says also says
Test value !0-9@
translates totest_value_0_9
: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/tests/Drupal/... 🧐Comment #138
leymannxOkay, I reverted the commit. That wasn't it.
Comment #139
leymannxOkay, I found a way to output the machine name value from the field and it's a completely different value than the one that's expected:
jvfavt8z == test_value_0_9
wich of course isfalse
. Same can be seen in the test artefacts.It's also the same what I experienced after I put
$settings['extension_discovery_scan_tests'] = TRUE;
into my settings.php and enabled theentity_test
module. I opened URL/entity_test_string_id/add
and it always contained some random name in the name field and the machine name field was always pre-filled with this machine name. When I changed the name, the machine name didn't change accordingly. It always stayed the same.(It also looks really different from all other machine name elements I know in Drupal.)
By the name of Dries I couldn't find where this arbitrary name value was coming from. On every page load it was a different one. I also don't understand why all other asserts succeed and only this one doesn't.
Does anybody here have an idea why when accessing
/entity_test_string_id/add
the name is always pre-filled with a random value? Where does it come from?