This is an issue derived from the meta issue #1770720: [META] Gradual changes to Field UI and #1786198: Make consistent regions in code for fields UI overview screens.
The changes abstract common behavior into base functionality for the manage fields and manage display screens.
It will also include some very minor changes which add consistency between the two screens.
Form UI functions
Basically this is a straight forward copy from the old form functions into a subclass of Drupal/field_ui/OverviewBase. There are no major changes inside the form api code.
Two alter hooks that were added in core later on (during re-roll) were added here too. For the rest everything is the same. The real refactoring to make it consistent will be done in #1786198: Make consistent regions in code for fields UI overview screens.
The list of changes:
- previous drupal_get_form from router item is changed to a page callback that load the forms from a class method.
- $view_mode became $this->view_mode
- $bundle became $this->bundle
- $entity_type became $this->entity_type
- regions are defined in the Overview object
- Added hook_field_formatter_settings_form_alter
- Added hook_field_formatter_settings_summary_alter
- validate and submit handlers are addressed through OOP methods (and added inside the form function)
Follow-ups
- Moving the variables to $form_state['key'] instead of $form['#key'] is a follow up
Comment | File | Size | Author |
---|---|---|---|
#44 | 1792600-44.patch | 101.33 KB | fubhy |
#41 | 1792600-41-for-commit.patch | 97.38 KB | fubhy |
#40 | 1792600-40-for-testing.patch | 101.9 KB | fubhy |
#40 | 1792600-40-for-commit.patch | 99.94 KB | fubhy |
#39 | 1792600-39-for-commit.patch | 97.68 KB | fubhy |
Comments
Comment #1
Stalski CreditAttribution: Stalski commentedThe patch which includes the nid.
Comment #3
Stalski CreditAttribution: Stalski commentedRerolled and some stuff was just uncommented, not removed.
Comment #4
Stalski CreditAttribution: Stalski commentedthe patch :/
Comment #6
swentel CreditAttribution: swentel commentedLet's see what the bot says now.
Comment #7
swentel CreditAttribution: swentel commentedOh my, took the patch wrong
Comment #9
swentel CreditAttribution: swentel commentedFix last remaining tests.
Comment #10
Stalski CreditAttribution: Stalski commentedNice job swentel. Tested it and all keeps working without any visual change. Tests pass
Comment #11
swentel CreditAttribution: swentel commentedHmm no, #1303412: 'Manage display' : Cannot drag in or out of 'Hidden' got in, so this needs to be removed from the patch.
Comment #12
Stalski CreditAttribution: Stalski commentedYeah, just saw that, which is a good thing. I'l reroll the patch now
Comment #13
Stalski CreditAttribution: Stalski commented- reroll
- Additional change adding the invocation of drupal_alter so implementations of hook_field_formatter_settings_form_alter and hook_field_formatter_summary_form_alter work
All tests work.
Comment #14
Stalski CreditAttribution: Stalski commentedDoing some cleanups and rectifying documentation against http://drupal.org/node/1354#classes
Comment #15
Stalski CreditAttribution: Stalski commented- Added and changed documentation suggested by the Doxygen and comment formatting conventions.
- Changed some lines suggested by swentel (too long comments, capitalized words to lowercase, added (optional) )
Comment #16
Stalski CreditAttribution: Stalski commented2 other modificiations in commenting to make things more clear.
Comment #17
fubhy CreditAttribution: fubhy commentedAll I could find were some code-style and readability issues. The concept and the code look fine in general.
Normally, we are using non-camel-case variables.
Same.
Missing "."... Should be "Implements Drupal\field_ui\FieldUIOverviewInterface::getRegions()." Same for all the following method docblocks.
Empty line for no reason.
Exceeds 80 characters.
Exceeds 80 charaters.
Exceeds 80 characters.
Exceeds 80 characters.
Exceeds 80 characters.
Missing "." after Implements ... (Here and everywhere else too).
Comment too long :)
"A renderable array"
Here too!
Comment #18
nils.destoop CreditAttribution: nils.destoop commentedReviewed this, and everything seems ok. I think this can go to rtbc after the comments from fubhy are applied.
Comment #19
Stalski CreditAttribution: Stalski commentedChanges according to feedback from fubhy.
Comment #20
andypostPatch size mostly caused by moving a big form code within files. I've done a manual testing - it works!
I think it RTBC
Better to use !== hidden (I've tested this change manually). If there could be more regions name... maybe this js could be re-used!
Patch allows to use a different region-set but there's a lot of hard-coded references to 'content' and 'hidden'. Maybe better to always have this "key-regions" by default?
This should be one-line, but let's leave it for follow-up with clean-up
Comment #21
Stalski CreditAttribution: Stalski commented@andypost: thx for the in depth review.
1) !== hidden was a suggestion. Dunno if that's for this patch. It might be postponed to #1786198: Make consistent regions in code for fields UI overview screens where consistency and expandability is the topic.
2) content and hidden are still hardcoded in this patch. It might be "detected" in #1786198: Make consistent regions in code for fields UI overview screens to actually make it less hardcoded.
3) the two line comment was just changed into 2 lines since it exceeded the 80 chars. Is this not needed in this case?
Comment #22
nils.destoop CreditAttribution: nils.destoop commentedReviewed and approved :)
Comment #23
Stalski CreditAttribution: Stalski commentedReroll against new head
Comment #24
Stalski CreditAttribution: Stalski commentedSorry, did not mean to change the status. Patch was the same I just saw.
Comment #25
yched CreditAttribution: yched commentedGreat work !
So as I said earlier, I generally +1 on the principle. I have a couple remarks on the implementation though - nothing serious.
- Aside from the code reorganisation, it's difficult to see the changes within the code that gets moved around (e.g. the actual content of FieldUIDisplayOverview::form() vs the former field_ui_display_overview_form()). Are there any, and if so, can you summarize them ?
- We don't need the FieldUI prefix in the class names. The namespace is specific enough.
- Too bad we still need to keep field_ui_display_overview_multistep_js() in the .module file
Have you checked whether field_ui_display_overview_multistep_submit() could work as a class method, though ?
field_ui_field_overview_form() and field_ui_display_overview_form() are not form callbacks anymore but regular page callbacks, that happen to return a rendered form. They should thus be renamed, to e.g. field_ui_field_overview(), field_ui_display_overview(), and their phpdoc be adjusted. See the phpdoc of entity_get_form() for an example.
When renaming, beware of code comments that still refer to the old form callbacks ("Form submission handler for buttons in field_ui_display_overview_form()", Handles multistep buttons in field_ui_display_overview_form()", "This function is used as a #region_callback in field_ui_field_overview_form()")
Not needed - 'implements' or 'overrides' is enough. Same applies to the other methods, unless there is something really specific to that given implementation you want to emphasize
Lacks type hinting in the signature (core type hints 'array' for arrays and class name for objects) and a proper docblock with @param and @return statements - same applies to other methods.
Minor, but looks like this could be moved to FieldUIOverviewBase::form() ?
Let's move those to $form_state (probbly best in a followup)
Not clear to me when this message would appear, but the wording seems weird.
Private methods are frowned upon, needlessly restrictive - 'protected' is sufficient. Same applies to validateAddExisting()
The properties should have a phpdoc block with a sentence and a @var statement.
Should be 3rd person : "Gets" - I didn't closely check the rest of the methods on this aspect.
"statically" caching seems overkill. I'm not sure we need a property for that, just proxy to the function.
Seems not too consistent to define an empty validate() here and not an empty submit().
I get that FieldUIDisplayOverview has no validation, but I'd rather see none in the Base and have both subclasses add explicit methods (explixitely empty for FieldUIDisplayOverview)
Language - "for Field UI overview pages" ?
No strong opinion here, but I don't really get why we need an interface. A base class, yes, but an interface ? Do we expect to have generic code that works on whatever FieldUIOverviewInterface object ?
We usually try to leave _construct() method out of interfaces. Different child classes might need different construction logic / params.
Misses an empty line after the last method - same applies to the actual class files
29 days to next Drupal core point release.
Comment #26
Stalski CreditAttribution: Stalski commentedthx a lot yched! I will refactor this today and rerolled it.
Form UI functions
There is nothing that changed inside the form api code. I did add two alter hooks that were added in core later on (during re-roll). For the rest everything is the same. The real refactoring to make it consistent will be done in #1786198: Make consistent regions in code for fields UI overview screens. So the only things that changed summarized:
Refactoring
Did not change
Well, that's in fact especially for the getRegions method. Should the interface be removed?
Follow-ups
Comment #28
yched CreditAttribution: yched commentedThanks for the changes, @Stalski - not easy for me to review code now, so I'll leave it to others to drive this home.
re: adminPath()
Yeah. Well then, why don't we just populate it in the construct and be done with it ?
re: interface :
Then maybe just put getRegions() in the base class as an abstract method and ditch the interface ?
Comment #29
Stalski CreditAttribution: Stalski commented- Yeah, just loading it in the construct is better actually. Changed that
- Ditched the interface and changed all comments like "overrides" and "implements" and the interface descriptions are moved to the base class.
Also fixed the errors for the previous patch:
- typecasting problem
- view mode was not passed along anymore, fixed that as well
Comment #30
Stalski CreditAttribution: Stalski commented#29: 1792600-29.patch queued for re-testing.
Comment #31
swentel CreditAttribution: swentel commentedThis looks good to me. The question is, should we wait for #1802072: Ajax callbacks should be callbacks defined as function or class method to get in first, or go ahead ? Could be done in a follow up of course. If anyone else can review the last one and think it's good, rtbc it.
Comment #32
andypost@Stalski please update issue summary from your last comments, and I think it's ready.
Actually there's big changes depends on this issue so let's get this commited and focus on
#1770720: [META] Gradual changes to Field UI
#1786198: Make consistent regions in code for fields UI overview screens
Comment #33
tim.plunkettIf these are hardcoded, they cannot be subclassed.
Comment #34
Stalski CreditAttribution: Stalski commentedWhy is this needed? Form altering is what people did in D7 and they still can do that.
Follow ups will refactor this even more, and one of the things could be to make it extensible as well. The point is you could run your own callbacks from the menu hook, creating your own Overview implementation in a field_ui contrib module for instance.
So my vote goes to postponing this to a follow up as extra feature. Besides most examples who will implement the field_ui will not be able to use extensions. One way would be the decorator way. (field_group, DS, ...)
Comment #35
Stalski CreditAttribution: Stalski commentedThought about this some more. Just setting this back to RTBC since this patch intends to get in soon without adding new functionality. That's the main reason why this issue was created from #1770720: [META] Gradual changes to Field UI and #1786198: Make consistent regions in code for fields UI overview screens
Comment #36
tim.plunkettThanks, I feel better already :)
+1 for RTBC
Comment #37
Stalski CreditAttribution: Stalski commentedNow that #1802072: Ajax callbacks should be callbacks defined as function or class method is in, I wil take this even futher as yched suggested and take the multistep js for configurations to the FieldsOverview object, or should this be in a follow-up and leave this RTBC? If so, then we will take this further refactoring in #1786198: Make consistent regions in code for fields UI overview screens.
thoughts?
Comment #38
fubhy CreditAttribution: fubhy commentedDoesn't apply anymore anyways. Doing a re-roll!
Comment #39
fubhy CreditAttribution: fubhy commentedSomething went wrong when #1802072: Ajax callbacks should be callbacks defined as function or class method should've been commited/pushed. Anyways. I re-rolled this one (didn't apply anymore). And created two patches for now (one, that incorporates the Ajax method callback patch for testing and one that doesn't [which is going to fail]).
Comment #40
fubhy CreditAttribution: fubhy commentedWhoops, accidentally I killed the changes to operations introduced by #1480854: Convert operation links to '#type' => 'operations'. Re-adding those in this patch and also removing a few lines of stale (unused vars) code that I found while doing so.
Comment #41
fubhy CreditAttribution: fubhy commentedToo impatient.
Comment #42
fubhy CreditAttribution: fubhy commentedSo the fact that the patch in #41 passes the tests maybe proofs that we need more field ui tests. It shouldn't pass considering that it uses the new ajax OO method callback from #1802072: Ajax callbacks should be callbacks defined as function or class method which hasn't been pushed yet.
Comment #43
andypostPlease format this as one-line summary according http://drupal.org/node/1354#functions
Comment #44
fubhy CreditAttribution: fubhy commentedAnother re-roll due to the recently pushed field formatter plugin-ification patch. Also incorporates the changes suggested by @andypost. The #ajax method callback patch is in now as well and also incorporated in this re-roll.
Let this be the last re-roll please :).
Comment #45
Stalski CreditAttribution: Stalski commentedThx fubhy. It looks good imo.
Comment #46
catchOK this has been RTBC for a while and was just stuck in re-roll hell.
I reviewed the patch, and while I'm not entirely comforable with the form callback as class model one-offs we're introducing for entities, it's probably as close as we can get for re-using that code in Drupal 8, so committed/pushed to 8.x. Hopefully this will unblock some more work.
Comment #47
fubhy CreditAttribution: fubhy commentedFound a minor bug in this patch: @see #1824180: Undefined variable $admin_path in Field UI module
Comment #48.0
(not verified) CreditAttribution: commentednow it's RTBC, we can add the actual work done here