Problem/Motivation
The creation of menu links was hard-coded at the Node API.
This feature/UI is mostly for content creators, not for site builders.
This is problematic for various reasons:
- It adds a dependency of people using the menu_ui and menu_link_content module, even they don't have to necessarily
- It makes it impossible for other entity types to get the same features
- Solving that in a generic way for any entity helps to make the workflow more consistent
Proposed resolution
- Separate the Menu Links as an independent module, which provides a menu link field. That field holds the representative menu item(s?) of the entity.
- Create a new field type / widget / formatter to allow the creation of (representative) menu links when an entity having that field is created or edited.
- In an update hook, if menu_link_content module was enabled and menus were selected in the node type menu settings, automatically add the field to that node type and move the settings to the field.
- Provide full Views integration allowing to access the referenced menu item's (also see #2777749: Add menu_link_content support into views):
- Entity data (e.g. menu, title, description, status, weight, parent menu item id, ...)
- Relations (e.g. referencing entity <==> menu item, menu item => parent menu item, (menu item => children menu items?))
- Optionally: Helpful additional data, e.g. menu level (menu items depths level) to filter or sort by
- ...?
- Deprecation of work-around contrib modules for non-node entities like
- Possibly deprecation of other work-around contrib modules which were not solved in core yet. (TBD what's in / out of scope here):
- https://www.drupal.org/project/menu_item_extras
- https://www.drupal.org/project/menu_entity_index (https://www.drupal.org/project/menu_node in Drupal 7 - with > 5.600 installations!)
- ...?
This was an always-planned phase 3 of the menu link plugin plan #2256497: [meta] Menu Links - New Plan for the Homestretch Proposed solution has so far been implemented as a contrib module: https://www.drupal.org/project/menu_link
Remaining tasks
- Discuss (points from above and the discussion):
- General functionality
- Revisioning (#182)
- Entity <==> Menu item relation tracking
- Views integration
- Update path / migration
- Contrib deprecations
- ...?
- Plan
- Review https://www.drupal.org/project/menu_link
- Plan possible differences and additions
- Plan update path (see above)
- Implement & Test
- Create a MR for core based on contrib menu_link
User interface changes
Added field and widget to be used at nodes (replacing menu_link_content's special functionality for nodes) and other entities.
API changes
* Addition of API to save link menu for entities.
* We no longer use menu_link_content entities for node links, but rather put them into the menu tree storage more similar to the menu links
defined in YMl files.
Key & additional benefits:
- General entity support instead of custom code for nodes
- Better handling of relationships of menu items referencing entities and vice versa
- Views support (also for references)
- Search API support by design (by field) #3277308: How to use entities' menu item data as source fields?
- ...?
Comment | File | Size | Author |
---|---|---|---|
#165 | interdiff161_165.txt | 8.63 KB | Munavijayalakshmi |
#165 | 2315773-165.patch | 76.03 KB | Munavijayalakshmi |
#161 | 2315773-161.patch | 70.21 KB | dawehner |
#158 | create_a_menu_link-2315773-158.patch | 70.54 KB | Sutharsan |
#151 | create_a_menu_link-2315773-151.patch | 70.34 KB | jibran |
Comments
Comment #1
dawehnerSome initial work ... still needs for sure quite some work.
Comment #2
dawehnerSome work here and there. At least saving of them should actually work.
More work needs to be done on the menu link edit form ...
Comment #3
dawehnerThe general functionality somehow exists now.
Comment #5
dawehnerLet's try some basic reroll.
@pwolanin
Given the few failures we might could really push this to be green.
Comment #7
dawehnerThere we go, everything beside one stupid failure is fixed.
Comment #9
andypostthis depends on menu_ui but I found no field dependency.
fields are provided by core
Comment #10
BerdirAnd you can probably avoid the dependency on menu_ui, because that function is just a very simple wrapper for returning all menus, if you don't use the optional argument.
Comment #11
andypostalso module contains only a field so maybe better to put it inside "menu_link_content" module and update its description
Comment #12
dawehnerGood idea, let's avoid the dependency.
Well, its an orthogonal idea to menu_link_content, kinda the other way round actually. In menu_link_field you start with the entity and attaches a menu link to it.
There we go ...
Comment #13
Wim LeersBiggest concern: I'm wondering if this really belongs in a separate module, or whether it belongs in core.
Review below. Ideally, pwolanin would also review this, because I didn't work on the form aspects of menus at all during the "homestretch" patch.
A new method on something as deep as this — needs sign-off from fago/yched/Berdir probably?
Great!
This comes with a huge tree of services it depends on. Perhaps not c'tor inject this?
It's not guaranteed the
main
menu will exist."content type" implies this will only be used for nodes. Seems wrong.
Where's the actual link itself?
Consistency with the labels in
propertyDefinitions()
?- The menu link title.
- s/link/menu link/
Why does
FieldItemInterface::preSave()
exist, but not::postSave()
? That would allow us to remove most of the unclarity here.Regarding
doSave()
: I think you can copy most of the code (not docblock) comments fromMenuLinkContent::postSave()
, which is where it looks like you found this?Should have a newline in between.
s/menu_link_item/menu_link/
s/menu parent/parent menu link/
Let's negate this, so that the else block can come first, which is much shorter, so you're not left wondering why this is wrapped in an if-statement.
$this->t()
Black magic!
Missing docblock.
Should explain why this must live in a
#pre_render
callback.s#menu/parent#menu and parent menu link#
s/field based/field-based/
Comment #15
pwolanin CreditAttribution: pwolanin commentedI think this is critical, since otherwise we are not going to be able to solve the WTF of content menu links referencing "objects"
Comment #16
Mac_Weber CreditAttribution: Mac_Weber commentedI have fixed what @Wim Leers had pointed, except for:
It seems the Main menu is always available
It did not pass some tests for "Drupal\system\Tests\Menu\BreadcrumbTest" at my localmachine, but I am sending the patch anyway because these tests were failing even in a clean git repo. I hope it works for the testbot.
Comment #18
dawehnerIt is fine to not fix, that logic was there before the patch as well.
Comment #19
Mac_Weber CreditAttribution: Mac_Weber commentedComment #20
Mac_Weber CreditAttribution: Mac_Weber commentedComment #21
pwolanin CreditAttribution: pwolanin commentedSome of these cleanups could go in a separate patch to make this easier to review:
Comment #22
pwolanin CreditAttribution: pwolanin commentedSo, I feel like were taking a step backwards here:
I'd want to check if the site is multi-lingual and try to get a translation like we do for menu link content entities?
In other words, if you translate the node this field is on, you should be able to automagically get that as the title:
Comment #23
pwolanin CreditAttribution: pwolanin commentedPer the above - I think this field shouldn't store the title at all, it should just use the entity label.
Comment #24
pwolanin CreditAttribution: pwolanin commentedSome really outdated test code in the breadcrumb test is seems?
Comment #25
pwolanin CreditAttribution: pwolanin commentedHere's a first pass at fixing, but getting a recursion error in the node form.
I think taking the title from the entity is really the 90% use case and what we should do for the field. In the 10% case of needing a different title, you can make a custom menu link.
Note also that this means content translators don't need 'administer menu' permissions, which they would if they need to access the menu link field in order to translate it.
Comment #27
dawehnerI'm sorry but I think not supporting title/description again WILL make that issue much harder than we want, given that it changes the UI
of the node form. In case you want to change the UI, just make that optional somehow or fix that later.
That one was certainly wrong. Good catch!
I am not convinced that we need to do this optimization now and here ... We could multi load also on the tree manipulation level, in case you really want it to do. The interdiff shows how it could work.
Comment #29
martin107 CreditAttribution: martin107 commentedThe patch applies, but I am getting some funny FieldStorageConfigStorage errors at site install so retesting
Comment #32
martin107 CreditAttribution: martin107 commentedI can see ONE thorn in the lions paw.
Comment #33
martin107 CreditAttribution: martin107 commentedTrivial nudges in the correct direction ...
DefaultMenuLinkTreeManipulatorsTest now passes.
Comment #34
martin107 CreditAttribution: martin107 commentedComment #36
yoroy CreditAttribution: yoroy commentedI was hoping to get a screenshot but patch is not simplytest compatible yet :)
Comment #37
martin107 CreditAttribution: martin107 commentedDefaultMenuLinkTreeManipultors::loadEntities() now passes along the tree parameter.
SystemMenuBlockTest now passes and site install now works.
Comment #39
pwolanin CreditAttribution: pwolanin commentedI think we should pull out the entity loading changes from the menu try and try to focus just on getting this all working smoothly before optiizing.
Comment #40
webchickWe discussed this on our core committer D8 triage call today, and couldn't come up with a firm decision on whether this is critical, so tagging accordingly.
Comment #41
dawehnerSimplified stuff again.
Comment #43
larowlanschema stuff
Comment #44
dawehnerRemoved some of the just somehow related hunks (added the node access optimization in more places)
Struggling a bit with config schema today.
Comment #48
dawehnerBrought back the title/description functionality to have a similar behaviour to HEAD.
This helped to fix the remaining test failures.
Comment #49
plachThis is looking great, aside from the things below:
:)
This should be
'translatable'
, I think.However I tried to manually test it and I have a few remarks:
Comment #50
dawehnerHAHA, I should have tried my changes from this morning (removing - out of existing code seems not that bad, as expected).
Good point, basically all are really good points.
Changed that.
Couldn't address the other points in the meantime yet.
Comment #51
plachComment #52
chanderbhushan CreditAttribution: chanderbhushan commented#50 apply successfully
Comment #53
idebr CreditAttribution: idebr commentedAfter applying this patch I lost the linkage between existing nodes and their menu links, eg. menu links that were previously selected in the node edit form were no longer visible in the node edit form. I don't know if an upgrade path is in scope?
In the same category, I got a notice on an existing node and the tab with 'Menu settings' did not show up at all.
Comment #54
dawehnerThere has been both a wonderful drush only based interface for making configurable fields as translatable (see tells ;)) and bugs in the existing code.
Now you can translate the actual content entites and it works as expected. Pretty neat!
Berdir and I talked a bit about that and we consised to maybe add the menu links to every node type using the same mechanism as body fields and OR using
hook_entity_base_field_info_alter()
.No it is not at that point in time.
Comment #55
pwolanin CreditAttribution: pwolanin commentedI don't think we should add this to every node type - it's currently configured via the node type edit form. Adding a field is really at the same level imho, though perhaps less obvious to new admins. So, we should give them an example via the standard profile.
Also, let's kill the title-copying JS? In HEAD it's not possible to leave the title field blank, if you do no link is created. With this patch, I think blank and using the label (and it's translations) should be the default behavior.
Comment #56
webchickWhy would we revert that usability improvement that goes back as far as D6?
Comment #57
pwolanin CreditAttribution: pwolanin commented@webchick - the idea being if you leave it blank it just uses the node title (label) and hence you could also get the translated title for free.
To be clear - I do *not* want you to have to type a title, I'm trying to make it more automatic. Perhaps even have the field hidden with a checkbox that says "customize link title"
In any case, this can wait to a follow-up if it's going to extend the debate since it's UI tweaking, rather than anything fundamental.
Comment #58
webchickOk, I'm glad to hear we're not thinking of removing that UX feature. But yeah, let's discuss it more in a follow-up since ideally this one would just match the existing UX with different backend stuff.
Comment #59
dawehnerComment #60
yched CreditAttribution: yched commentedCannot do a full review atm, but :
In other widgets we've tried hard to use static methods for this kind of FAPI helpers (added in the $form as [get_class($this), 'methodName'] rather than [$this, 'methodName']). Avoids needlessly serializing the Widget object as part of the $form serialization.
Comment #61
dawehnerFair, I don't have a problem with that.
Comment #62
plachCan't we use
ContainerFactoryPluginInterface
here too?"the" can go in the previous line, perhaps also "menu".
I'm not sure whether this check needs to be dynamic or static, but in the former case I'd use
is_subclass_of($entity, '\Drupal\Core\TypedData\TranslatableInterface') && $entity->isTranslatable()
, otherwise I'd simply use$entity->getEntityType()->isTranslatable()
.Please, use
$entity = $this->entityManager->getTranslationFromContext($this->getEntity());
here, so we can apply also language fallback. TheTranslatableInterface
hint is not needed, asEMI::getTranslationFromContext()
accepts any entity.Comment #63
plachOh, I forgot: this works beautifully now :)
Only one remark left: we are still missing the JS behavior hiding all widget elements when the checkbox is not checked:
This is an important UX fix, because values entered in the widget text fields are silently ignored if the checkbox is not checked.
Comment #64
dawehnerMh, this works fine for me ... do you see some JS errors on the page, maybe?
Comment #65
dawehnerThank you a lot for the review.
Please enlighten me, but I have no idea where I could get
from.
The second alternative sounds sane.
Ah, this is much better.
Comment #66
dawehnerNot sure what is going on, but it worked for me. (I can send the video if someone needs a prove)
Comment #67
dawehnerNot sure what is going on, but it worked for me. (I can send the video if someone needs a prove)
Comment #68
Berdir@dawehner: That is built into TypedDataInterface:
Comment #69
plachIt seems #63 is a browser issue: Safari 8.0.2 and Firefox 34.0.5 (on Yosemite 10.10.1) are not working, Chrome 39.0.2171.95 is.
Comment #70
plachThis is definitely something that should go in before we support an upgrade path.
Comment #71
dawehnerThat is a problem which is better solved at another day.
Comment #72
dawehnerSo it turns out, unlike as #68 said, it is not built into the TypedDataInterface.
Worked a bit on the issue summary / beta evaluation.
Comment #73
plachI tried a slightly more advanced multilingual use case: having different menus with different menu items for different languages:
Expected result: I would get two menu items, one for each translation.
Actual result: only one menu item is created and things are breaking.
Here is my DB dump if you want to skip the setup phase, codebase is 84e2b6d2 + #65.
Comment #74
plachComment #75
dawehnerThank you for your testing @plach
Interesting idea for the usage. Note afaik HEAD also doesn't support that usecase right? It just creates one menu link entry, that is all:
For me it seems to be that there are two kind of usecases.
a) you want to have one menu link, with simply translates the label
b) you want to have two distinct menu links, in two different menus.
Note: A menu tree entry is always tackled to a specific menu, the translation works on runtime, when the link is rendered.
Comment #76
pwolanin CreditAttribution: pwolanin commentedIndeed - core doesn't allow adding one link to 2 menus. However, you should be able to make a multi-value menu link field if that's your use case?
Comment #77
pwolanin CreditAttribution: pwolanin commentedOk - from IRC I understand the problem better: when you are translating the link field it allows you to change the menu-parent, but the menu-parent value is shared across all translations - it's not translatable itself and so we need to hide it or otherwise clarify the UI as a 1st fix.
Comment #78
Gábor HojtsyThere are two translatability use cases:
1. I mark the menu field translatable. In this case, there would be different menu values per language entirely according to our usual pattern. If I mark an integer field translatable, different languages have totally different integers on them.
2. I don't mark my menu field translatable but my menu link content entity is translatable. For this case as per MenuLinkContent::baseFieldDefinitions() only title and description is supposed to be translatable (=== marked with setTranslatable()). The widget would need to expose these as translable IF the menu link content entity referred is translatable. I think supporting separate menu items in this widget would be overkill. If I need separate menu items per language, I would mark the field as translatable, see point 1.
Here I made this handy figure for you, see attached :) MF: menu field, HU, IT, ES: languages. Looking at the patch, you marked the menu fields translatable, which suggests you also want to support (1) in some way?
Comment #79
idebr CreditAttribution: idebr commentedAttached patch fixes the #states on the menu widget.
Comment #80
Gábor Hojtsy@pwolanin and @dawehner pointed out on IRC that the field is not referring to external entities anymore and all menu item related data is within the field. I think in this case the file field style column synching feature is in order here. See FieldTranslationSynchronizer.php and:
You define translatable column group in column_groups which are then exposed as translatable settings:
It should be checked if the columns you may want to exempt from translatability are properly synced as well by FieldTranslationSynchronizer. I don't know enough about the column_group handling to tell if you can leave out columns and then what happens to them, but that looks like what you are looking at.
Comment #81
pwolanin CreditAttribution: pwolanin commentedI think we should add this in a follow-up issue. We need to just get this field in as a replacement for existing functionality first.
Comment #82
Gábor Hojtsy@pwolanin: in that case you need to make the field type explicitly not support translation; otherwise people can mark the field translatable and set entirely different menu items per language ATM. If you cannot / don't want to support that for some reason, then you need to deny that on the field type level for this iteration. The current patch sets default config for the menu fields as translatable and defines the field type as supporting translation as well, so when I enable my node type for translation, the menu item is currently translatable with all its values using this patch.
I don't advocate not implementing translation support of course, but if moving forward faster is more important, then so be it. I would assume the followup to make it multilingual would need to be critical as well then.
Comment #83
plach@Gabor:
I tested the current approach and it works fine if you limit yourself to menu item localization: you can translate title and description (and even weight) and it works just fine. We can lock the menu parent select for now, so one cannot select a different menu for each translation and then fix this properly in a (major?) follow-up.
@Peter:
To determine whether the menu parent select should be locked you can use:
Comment #84
pwolanin CreditAttribution: pwolanin commentedOk, after long discussion with Gábor Hojtsy, plach, and dawehner: for now we will simply disable certain widget fields when in a translation and only update the menu link definition when saving the original (untranslated) entity.
It would be better to use the functionality from \Drupal\content_translation\FieldTranslationSynchronizer but that has a bug in that it doesn't sync columns that are omitted from any column groups in the annotation. We will tackle that as a follow-up once this bug is fixed #2403455: FieldTranslationSynchronizer does not sync columns that are absent from any column_group in the annotation
Comment #85
pwolanin CreditAttribution: pwolanin commentedok, here's a patch that fixes a bug with the default value, solves some of the bugs around translation forms, and removes the parent field from fieldSettingsForm and from the config and schema since it wasn't being used (was a carry-over). If we want to do something like that we should override the default value widget.
Started adding a test specific to the new field.
Comment #87
pwolanin CreditAttribution: pwolanin commenteduh, forgot some annotation
Comment #88
pwolanin CreditAttribution: pwolanin commentedPut back the config and gave it a hopefully less confusing name.
enforced a cardinality of 1 using a trick from larowlan from comment module (though hopefully a better API coming soon)
suppressed the default value form since we don't want to use it and it was causing config schema mismatches.
Added a default menu parent select form to the field config, though that could probably use some work (need to apply some validation, or some ajax)
Comment #89
mikey_p CreditAttribution: mikey_p commentedLooks like @idebr's changes from #79 didn't get picked up.
Comment #90
pwolanin CreditAttribution: pwolanin commentedoh, indeed - thanks. I didn't see that fix
Comment #91
Gábor HojtsyThere is no test coverage apparent added for this one. Am I seeing that right?
Comment #92
pwolanin CreditAttribution: pwolanin commented@Gabor - well, it doesn't have any effect due to the other bug, but what kind of test coverage would you want?
Comment #93
aspilicious CreditAttribution: aspilicious commentedTested this and this going in the right direction :).
2 remarks probably other issues
1) When going to the menu overview you can't delete the menu links defined by content. Pretty annoying.
2) I still don't see the possibility to localize to any other menu item that is not content related. Are we going to fix that in core?
Comment #94
dawehnerWe talked about that quite a lot and decided that we won't do that as part of this patch, given that it adds new levels of complexity. In general
though we can work on that later.
Worked on that.
Comment #95
dawehnerOh btw. I tried to write the test coverage mentioned in #91 but failed really early, so for now this patch just includes what is needed.
Comment #97
pwolanin CreditAttribution: pwolanin commentedSo, I think we might be better off with a generic delete form instead of making one specific to the field? How about this instead? MenuLinkDeleteForm is almost identical to MenuLinkResetForm - both under menu_ui. If menu_ui module is off, we don't need a delete form for the field, since it's just managed via the entity edit form.
I'm not yet sure what's failing in the new test, since it's running a bunch of generic content translation logic.
Comment #98
Gábor Hojtsy@pwolanin: if you don't expect the column_group annotation to do anything, then why include it? It makes the appearance that this is supposed to work. I don't think its a good idea to add code that would not even do anything? (Looking at the current patch in #98 the whole field type is missing, I assume that is a mistake).
@dawehner, @aspilicious: prior to this patch at least there are three ways to translate/localize a menu item depending on where it came from: (1) menu link content entity is translated as content via their fields (2) config exposed menu items such as views created items are translated within the views configuration (3) hardcoded menu items in modules are translated as part of the software (locale module UI). All of these have core UIs. All three UIs are different. It looks to me like all of these 3 sources for menu items are kept, so those should work. However this patch adds the menu item direct on the menu plugin manager with verbatim data instead of providing a derivative class like views does (see Drupal\views\Plugin\Menu\ViewsMenuLink). If this way of adding the menu item is to be kept then the menu plugin manager will need ways to support the translation of these items. That to me looks like work additionally to making the field data itself translatable. Until those two are done, this patch will be a regression for multilingual support (which is why I said we need the followup for that critical d8 upgrade path issue or resolved here).
Comment #99
dawehnerGiven that each implementation is pretty much non-cacheable via that, I argue that it odesn't make sense here to return a access result and not just a boolean.
Did you tried that out? We support translating the label, much like we do in HEAD. Do you think it is a critical requirement
for this patch to support moving translated menu links into a different menu? I am not sure, but I don't think HEAD supports that as well at the moment.
Comment #100
Gábor Hojtsy@dawehner: you are right, I did not see MenuLinkField::getProperty(). So that combined with how the widget is currently coded indeed makes it possible to swap title, description and weight per language. The other translation methods don't allow for translating other things either (and for the matter, none other would let you "translate" the weight).
Reading the code then, I had this concern but cannot reproduce yet:
1. You create a site with 2000 articles.
2. You enable translation for articles.
3. Now you can translate menu items for all 2000 articles (the UI works), but it will not appear actually translated until you re-save the entities.
That looked to me due to how MenuLinkItem::doSave() "caches" the translatability of the container entity's type in the menu definition (via MenuLinkItem::getMenuPluginDefinition()), but only if the original language version was saved. The widget does not care for that cache but the MenuLinkField::getProperty() does, which is what is being used for providing the item at the end.
I may not be able to reproduce this because I used the site as an admin and then I have untranslatable fields as well which are saved to the original entity, so the original entity gets saved all the time. I should produce an environment where I am testing as a translator only so the original is not saved then (assumed for now :).
Comment #101
Gábor HojtsySet up a scenario with a translator role/user who had access to translate but not to administer content. Cannot reproduce the suspect menu bug from #100 because the menu field did not even appear. Not sure where is the logic for deciding which fields are "administer content" level fields, but menu items can now only be translated if you also have that, which sounds like the first problem to resolve before the one I suspected in #100.
Comment #102
dawehner@Gábor Hojtsy
The permission you need is 'administer menu' in case you want to able to configure that. This mimics primarily the behaviour of the custom node form in HEAD.
Comment #103
Gábor Hojtsy@dawehner: yeah I did not expect to need the administer menu permission for translators (and therefore providing them an avenue to change anything in any menu) to be able to translate menus. That permission is NOT needed to translate any of the other menu items that I know of. With that permission granted though, it still works and I cannot reproduce the suspected bug in #100. I think we should have an API level test to ensure that the "original is saved when the translation is saved" is happening there too, because that is pre-requisite that this works for existing entities that were created before you made the entity type translatable.
Comment #104
pwolanin CreditAttribution: pwolanin commentedoops - this is the patch that was supposed to be on #97 - I posted the wrong patch.
Comment #105
Gábor HojtsySo a key realization is the menu definition caches the translatability of the **entity type** such as node, user, etc. This is coming from the annotation and is not configurable. Configurability is for the bundle level. That is NOT saved here.
So my concern that change of translatability would be a concern when changing configuration is moot because this is not configurable, it is on the entity type definition level.
That means that this will look up translations for entities on multilingual sites all the time even if they cannot have translations ever. Fixing that would be an optimization and is fine to be done in a followup.
Back to needs review.
Comment #106
dawehnerThis is just an interdiff for a potential test in the future.
Comment #108
pwolanin CreditAttribution: pwolanin commentedre-roll to fix conflicts.
Comment #110
pwolanin CreditAttribution: pwolanin commentedSo, I'm not sure wether it's worth including the translation test right now - changing the class so it extends NodeTranslationUITest seems to pass, but I'm not sure it's giving any useful new test coverage.
Comment #111
Gábor HojtsyYeah the MenuLinkFieldTranslateUITest in this latest patch does not actually test translating menu items AFAIS. It has code to add permissions to editors, admins and translators to do it but no code to actually do it. If this patch strives to implement menu translation, it should test translating the supported items IMHO. Otherwise we are adding untested code.
Also as discussed the actual problem with the UI based solution to limiting what you can translate as done in the patch is that it does not solve problems in the API. There is no protection for the API level to not mess up everything. If I do this:
Then depending on what language $node was at the time, will only update one translation with a different menu name, which may or may not end up actually changing the menu name on the item given you take the value only from the original language.
Solution is to either not let menu name be modified when you update a translation (throw exceptions, more custom code on your side) or implement column_groups / FieldTranslationSynchronizer which would actually sync the updated value to all languages in the above case transparently. Of course that would require #2403455: FieldTranslationSynchronizer does not sync columns that are absent from any column_group in the annotation to be resolved. So long as that is a followup, we need to accept that this patch will be on shaky ground for field translation as the API is concerned.
Comment #112
pwolanin CreditAttribution: pwolanin commentedOk, do you have another example we can start from? ContentTranslationUITest seems to be doing too much - maybe we need to start from ContentTranslationTestBase?
@Gábor Hojtsy - we could implement some manual synch, but in general I think we are trying to get the UI and the field storage in place here so we could make later changes without needing schema/data changes (i.e. so we are not blocking the upgrade path).
Comment #113
dawehner@Gábor Hojtsy
I ask myself wether we really need it, if we want to support different menu parents in future issues.
@pwolanin
Ah extending sounds partially helpful. If we do that, we could really easy just add some additional assertions and be done.
Otherwise we could implement an example for test entity types as well.
Comment #114
Gábor Hojtsy@dawehner/@pwolanin: re #113 the current patch makes the implementation possibly problematic for API consumers, that should not stop the patch from being committed IMHO but the followup needs to be critical to resolve it AFAIS or we have a fragile API.
@pwolanin: re tests, I think extending from ContentTranslationTestBase is cleanest, you don't want all the extra tests on NodeTranslationUITest to also run in your tests the same way. Alternatively adding new test methods directly to NodeTranslationUITest is an option as well. If matching menu item support for all entity types is a concern, then you can add new test methods in ContentTranslationTestBase itself as well, but not sure menu items on comments is something you strive for :) I think we can be fairly sure if it works on nodes translation-wise, it will work on other entities. Unless there is node specific code to support translation of it which I don't think there is.
Comment #115
pwolanin CreditAttribution: pwolanin commentedpostponing this since we are having a meeting about whether to change direction
Comment #116
andypostAlso there's related #2235457: Use link field for shortcut entity
Comment #117
webchickI believe in the mega-menu links meeting we determined that this issue is no longer a release-blocker for Drupal 8. It would be great to replace the one-off form alter stuff in node module with a field that could go onto any entity, but since we've gotten by fine in Drupal 5+ with the form alter stuff, we can ship without it.
Comment #118
pwolanin CreditAttribution: pwolanin commentedI would say 99% we'll kick this to contrib, since any generic solution in core would be essentially interacting with an entity reference instead.
Comment #119
pwolanin CreditAttribution: pwolanin commentedmoving some generic bits of the patch to #2408275: Create a generic menu link plugin delete form in menu_ui module
Comment #120
Wim LeersWe're no longer changing direction.
I think we can now discuss the final fate of this issue?
Comment #121
dawehnerI'd even say a lot of the code still works
Comment #122
Wim LeersEven better :)
Comment #123
larowlanThis would potentially solve the fact that menu links that point to nodes aren't deployable at the moment.
We're hitting issues with default_content.
Comment #124
dawehnerThat makes it almost a bug, but well, there are other workarounds for that.
Comment #125
pwolanin CreditAttribution: pwolanin as a volunteer and at Acquia commentedI was also thinking that this field type (or something very much like it) could be created as a replacement for the way book module handles hierarchy so it could be applied to any entity type.
Comment #126
dawehnerPushed the patch to a contrib module http://drupal.org/project/menu_link_field without any testing.
Comment #127
dawehnerAt that point certainly a 8.1.x feature
Comment #128
dawehnerRerolled the latest iteration.
Comment #129
pwolanin CreditAttribution: pwolanin as a volunteer commentedre-rolled for conflicts in MenuNodeTest.php and menu_ui.module in 8.1.x.
Marking NR to check tests only
Comment #131
dawehnerRerolled but nothing else.
Comment #133
martin107 CreditAttribution: martin107 commentedNo working on the failing tests yet
1) MenuLinkField - EntityManager is deprecated. plumbed in the relevant replacements EntityTypeManager and EntityRepository
2) MenuLinkItem converted a few cases of t() to $this->t()
3) Fix lots of minor nits while running the new files through phpcs.
Comment #134
martin107 CreditAttribution: martin107 commentedswitched changes in #133 to use EntityRepositoryInterface.
Comment #137
martin107 CreditAttribution: martin107 commenteddrat ... my bad t() was used in a static function.
I think I may have introduced other errors .. I will fix them up
Comment #138
martin107 CreditAttribution: martin107 commentedComment #141
martin107 CreditAttribution: martin107 commentedLooking at the first failing test ... in the reroll confusion - core has changed a javascript's filename and we did not keep the patch in sync
The library definition attached in MenuLinkWidget::formElement() -- see library menu_link.form has a bad reference to "js/menu_link.js"
Is anyone familiar with changes in that regard?
Comment #142
dawehnerJust a reroll for now.
Comment #146
jibranReroll and fixed #2665992: @file is not required for classes, interfaces and traits.
Comment #148
jibranSome easy fixes.
Comment #149
dawehner@jibran++
Comment #151
jibranI think we have to keep deprecated schema for tests.
This JS might need an update.
Comment #152
jibranor add it to tests somehow to pass.
Comment #157
Sutharsan CreditAttribution: Sutharsan commentedWorking on this; re-roll first.
Comment #158
Sutharsan CreditAttribution: Sutharsan commentedComment #159
Gábor HojtsyComment #160
Sutharsan CreditAttribution: Sutharsan commentedThe failing test in MenuLinkFieldStandardTest. It fails because no menu link item gets created when creating an article with menu item. No record in the menu_tree table. The 'Provide a menu link' checkbox is off when re-editing a node to which a menu link was added. In code:
$this->menuLinkManager->hasDefinition($plugin_id);
fails to return a menu link definition.Some observations while studying the code:
There is no parent::insert and no ::insert in any of the inherited interfaces. Can this be removed?
The same here for ::update.
Comment #161
dawehnerRerolled for 8.4.x
Comment #163
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedComment #164
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commenteduse short array syntax (new coding standard).
PHP Parse error: syntax error, unexpected ')', expecting ']'.
Comment #165
Munavijayalakshmi CreditAttribution: Munavijayalakshmi at Valuebound commentedComment #167
pwolanin CreditAttribution: pwolanin as a volunteer commentedComment #168
dawehnerI just pushed an updated version to the menu_link contrib project which contains the latest patch of this issue + some fixes + an update path (not complete yet) as well as some additional multilingual capabilities (allow menu links to be per language).
Comment #169
dawehnerWhile working on this I stumbled upon #2861367: Field items lost on translations with empty values., a borderline critical, I think.
Comment #171
sylus CreditAttribution: sylus commentedJust wondering if there has been any movement on this issue? Definitely is a must have for multilingual sites, where it is hard to tell the content author they must use the menu item translation screen rather then the node itself due to:
- Gabor
I'm tempted to use https://www.drupal.org/project/menu_link project while waiting for this but was curious as to status.
Thanks everyone!
Comment #172
Wim LeersI stumbled upon this again via #2871591: Allow ComplexData in TypedData to specify computed properties that should be exposed in normalization and other contexts (which is finally unblocked). The issue summary of that issue says:
But D9 won't be allowed to introduce API breaks either, we'll have to do this in D8, while retaining BC, and then in D9 we'll be able to remove the BC layers.
Comment #173
Berdirtoken.module actually partially does that at the moment, that was the only way to make menu link tokens during node creation work, @larowlan did most of the work there.
But yeah, BC is fun here, the question is always what exactly makes up a BC break. I guess form structure and so on is excluded, so we could probably change it from custom code to widget, but it might also break token in fun ways if the field that token is trying to add suddenly already exists, but that risk always exists when adding new features/classes/fields and contrib had to do workarounds.
Comment #174
dawehnerThe one thing I was wondering: Is it really a BC break when we keep the old module around, so all existing sites can deal with it. New sites will get the new module and completely new code.
Comment #177
AnybodyEvery time I stumble up on this I think this would definitely make a LOT of sense and make Drupal 8 more consistent. This makes sense for every other entity type like Users, Taxonomy Terms, Commerce products, custom entity types... and would make everything so much better for menu integration.
I think we should put:
These are all kinds of filters / sorts / contextual filters we often used in Druapl 7 projects with custom modules, but should be core from my point of view to represent the menu / entitiy structure in views.
into the remaining steps, shouldn't we?
Also see #2804335: Provide menu item integration for views and #2777749: Add menu_link_content support into views which would be solved by this kind of general implemantation.
Comment #178
larowlanWe could do with an update on what needs doing here
Comment #179
fenstratAdding link to https://www.drupal.org/project/menu_link and removing outdated beta phase info.
Comment #182
johnwebdev CreditAttribution: johnwebdev commentedI've been evaluating and working on the current proposal in the Menu link contributed module during the past days.
I am concerned about revisioning the placement (menu, parent and weight properties) of the Menu link:
But we cannot make the properties non-revisionable! All configurable fields are revisionable by design and the properties inherits the revision support from the field. So this means we either need to make that possible, or we have to reevaluate how we can store the menu link data.
Edit: I'm not sure what caused that issue tag change. 🤔
Comment #187
AnybodyJust ran into this again and found a further benefit for the proposed solution and disadvantage of the current custom handling: Third party modules, like Search API can't access the current custom menu item implementation on nodes (and of course all other entity types). They also need custom implementations.
Background: I needed to add the menu items weight and parents to the Search API Fields (like for taxonomy terms) but that's currently not possible, as Search API doesn't know about the relations. (See #3277308: How to use entities' menu item data as source fields?)
I
'llEDIT: HAVE updateD the issue summary with additional information from #177 and #182.Perhaps @larowlan could review it afterwards, as someone with a lot more knowledge about core than me?
It would also be helpful if a core maintainer could have a look at #2777749: Add menu_link_content support into views which is closely related. That one could also need a decision how to proceed (combined or not with this issue).
Comment #188
AnybodyComment #189
AnybodyComment #190
AnybodyIssue summary updated! Please review and decide how to proceed. :)
Comment #192
quietone CreditAttribution: quietone at PreviousNext commentedChanging the 'D8 upgrade path' to 'upgrade path' because this is not yet tied to a specific major version.
Comment #194
alienzed CreditAttribution: alienzed commentedWould LOVE for this to be become reality. Our editors can no longer submit drafts because Drupal is complaining they are not allowed to change the Parent menu item (but it's just a draft!!!)
Comment #195
Anybody@larowlan, @quiteone and other core maintainers, any chance to give direction here as of #187?
I think feedback would make sense to allow further implementation. Thanks a lot in advance!
Comment #196
larowlanThe issue summary updates look good @Anybody
This is a difficult issue and there's still a lot to be done, the questions from #182 around revisions are excellent, @johnwebdev++
In terms of next steps, this issue needs a champion to keep pushing it forward.