Updated: Comment #N
Problem/Motivation
Path alias information can not be attached as a field to any entity type after #1980822: Support any entity with path.module, but path.module still has one-off form alters for node and taxonomy.
There's also the question of who should add it to the entity type, right now path.module alters it in for node and taxonomy, should it be condition in node/taxonomy instead? Would be a bit ugly, but that is what other entities would have to do anyway.
Proposed resolution
Convert it into a field widget, which would allow to easily attach it to any entity. This isn't about making it configurable (yet?), you'd still define it in code.
Remaining tasks
User interface changes
API changes
Comments
Comment #1
andypostIf we going to make it configurable field that we should care about cardinality then better to reopen #1751210-125: Convert URL alias form element into a field and field widget
The path module can provide widget and alter field info by allowing widget use.
Comment #2
berdirI just want to convert it to a widget here and not get derailed about configurable and UI and problems that come with that.
Here's a first patch.
Comment #3
berdirComment #6
andypostTests should use now
path[0][alias]needed here
Comment #7
yched commentedThere's no such thing as $element['path'] ?
Comment #8
sunI agree with doing baby steps. The original "Make Path a field" issue pretty much failed, because I tried to change too many things at once :P
Fixing the primary test failures revealed some more bugs:
Comment #9
andypost@sun I suggest you to add validation constraint as we do for fields like #2002168: Convert form validation of terms to entity validation
Comment #10
sunI'm not able to make PathLanguageTest work — the original English alias somehow seems to be gone after saving the French alias. I wasn't able to figure out why that is.
Comment #12
jibranInjection.
Comment #14
sunComment #16
berdirAccess should probably move to field access. That means we need a PathItemList class, specified as list_class on the annotation.
Then we can switch to $node->hasField('path') && $node->get('path')->access('edit') here.
Comment #17
andypost1) Fix #16
2) fix broken test -
interdiff2.txt3) the following addressed
Comment #19
andypostCurrently
Drupal\path\Tests\PathLanguageTestis broken some how, probably the order of alters with content translation...The node body field does not store translatable text, and language is not properly passed to new widget
Seems we need Gabor here
Comment #21
gábor hojtsyI don't think I could be in any way better authority than sun, Berdir and yched combined here :)
Comment #22
berdirHm. This seems to work... content_translation_entity_field_info_alter() is messed up, it doesn't correctly merge by-bundle settings of base field translatability. The first bundle just wins. That stuff is pretty messed up :(
I hoped that #2114707: Allow per-bundle overrides of field definitions would help a bit, but it doesn't.
As a workaround, we can set the article fields to translatable too, and use getLangcode() in PathItem().
Not so happy that Path now suddenly needs to be made translatable to work (once the form is saved, which is what the patch was doing) .
#2143291: Clarify handling of field translatability is related...
Comment #23
berdirUploading a patch usually works better than not doing so.
Comment #24
andypostThis is a ugliest hunk, any idea how to get rid of it?
Comment #25
andypost23: 2201051-path-widget-22.patch queued for re-testing.
Comment #27
andypostPatch removes @todo, and changes path language to
$items->getLangcode()as #23 doesLet's get @plach review on it!
Yes, we need to enable both bundles because of comment in
content_translation_entity_base_field_info_alter()Suppose related issue is #2111887: Regression: Only title (of base fields) on nodes is marked as translatable
Comment #28
andypostre-roll (library, details-open)
Comment #29
jibranmulti line please.
@param doc missing.
I think we have to add array before both the params
Comment #30
plachI also hoped #2114707: Allow per-bundle overrides of field definitions would help :)
Not sure whether that code was written making the wrong assumptions or it's just wrong. Anyway I think it's ok to set path fields as translatable, as written also below.
I couldn't find the part the the @see refers to. Anyway we might be able to simplify this code by using
$form_state['controller']->getFormLangcode(), but it seems the implemented logic is needed in theisUnique()call below.I think it's correct to set this translatable as path natively supports language.
Comment #31
andypostFix for #29
#30 1)
ContentTranslationController::entityFormAlter()consumes$form['langcode']that is set hereComment #33
andypostThere's no
ConfigField*after #2192259: Remove ConfigField.. Item and List classes + interfacesComment #34
andypostre-roll
Comment #36
andypostfix wrong merge
Comment #37
plachI still think this whole block of code could be simplified. Probably even
$entity->language()->idmight work as an argument to::isUnique().Comment #38
andypostbut this code set language for the whole node form!?
@sun suggest to file follow-up , here it is #2225977: Remove langcode manipulation by Path widget
Comment #39
plachOk with the follow-up from me, I posted a comment there.
Comment #40
sunFWIW, the change to use
setTranslatable(TRUE)for the path field definition appears to be in line with the changes that were performed by #2111887: Regression: Only title (of base fields) on nodes is marked as translatable — so hopefully that question is obsolete now.Didn't study the latest patch yet.
Comment #41
berdir36: 2201051-path-widget-36.patch queued for re-testing.
Comment #43
andypostre-roll,
isUnique()replaced withaliasExists()in 'path.alias_storage'Comment #44
andypostpatch
Comment #45
andypostnot included in last patch
Comment #47
andypostrevert this change
Comment #48
andypostforget to change
isUnique()Comment #51
berdirMissed one path.crud :)
Comment #52
andypostAnother re-roll
Comment #53
sunLooks good to me, thanks!
Comment #54
catchThis looks like good clean-up, although looks like we have work still to do to remove the form alters and/or have this configurable as part of the form display.
Committed/pushed to 8.x., thanks!
Comment #56
berdirI don't think Drupal 8 will have an UI for the sidebar/vertical tabs stuff, so I expect those form alter to stay, but only node needs it. Also when we switch to widgets for the node form, we'll still need to move them into the corresponding groups.
Comment #57
alexweber commented@Berdir correct me if I'm wrong but don't aren't form display modes the UI for vertical tabs stuff on entity forms?
Comment #58
amateescu commented@alexweber, nope, form modes just provide the option to arrange fields differently in various forms.
Comment #59
lokapujyaAfter this patch: When adding an entity reference field to an article via the UI, and saving the field settings (I used target entity of: content) I get the following:
Notice: Undefined index: columns in Drupal\Core\Field\FieldDefinition->getSchema() (line 484 of core/lib/Drupal/Core/Field/FieldDefinition.php).
I think it has something to do with pathItem being a "computed field" and not having a schema.
Comment #60
tstoecklerYes I found that bug in #2183231: Make ContentEntityDatabaseStorage generate static database schemas for content entities as well. The problem is that getSchema () should initialize columns to an empty array by default. See the latest patch there for example.
Comment #61
tstoecklerHere's the relevant hunk of that patch extracted. When I found this I didn't realize that this means that adding fields from the UI is broken. That makes this a critical bug. Instead of reverting this let's just commit the attached patch and add test coverage in a follow-up?
Comment #62
tstoecklerSorry, complete brain failure. Don't know why I thought of Entity Reference.
Comment #63
yched commentedLooks good to me.
Comment #64
sunThat internal Field API code wasn't touched by this issue/patch here, so that's a preexisting problem and the change of this issue is not guilty for that.
Created #2257769: Adding an Entity Reference field in the Field UI throws a PHP notice; fails to add field