Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
ForumForm
uses the old pattern of checking whether it is an add or an update form to provide dedicated messages.
Proposed resolution
Split ForumForm
into ForumAddForm
and ForumEditForm
instead. One additional complexity is that ForumForm
is extended by ContainerForm
.
Remaining tasks
User interface changes
None.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#70 | interdiff-2324871-68-70.txt | 1.96 KB | naveenvalecha |
#70 | 2324871-70.patch | 11.47 KB | naveenvalecha |
Comments
Comment #1
larowlanComment #2
Michael Hodge Jr CreditAttribution: Michael Hodge Jr commentedComment #3
Michael Hodge Jr CreditAttribution: Michael Hodge Jr commentedSo there is this function
It was in the old ForumForm file, and both the ForumAdd and ForumEdit will need it. Where is a good place to put it? I'd imagine I wouldn't want to duplicate the same function in both places.
Comment #4
larowlanComment #5
Michael Hodge Jr CreditAttribution: Michael Hodge Jr commentedThanks Larowlan!
Comment #6
Michael Hodge Jr CreditAttribution: Michael Hodge Jr commentedMy first attempt at this one.
Comment #7
larowlanassuming bot agrees I think this is +1 for rtbc
Comment #8
larowlanoh, and thanks @Michael Hodge Jr :)
Comment #9
Michael Hodge Jr CreditAttribution: Michael Hodge Jr commentedYou're welcome. Thanks for the help!
Comment #11
tstoecklerAwesome work on the patch. I was about to complain why you put actions() only on the edit form, but then I realized why and it makes perfect sense, really good catch!!!
Sadly I have two things I do have to complain about, where the second one at least would need to be fixed before commit IMO. Can you tackle that @Michael Hodge Jr?
Seems these parts could be moved to the parent implementation.
Even though ForumBaseForm actually sounds a lot better, our current standard dictates that this class should be called "ForumFormBase".
Comment #12
Michael Hodge Jr CreditAttribution: Michael Hodge Jr commented@Tstoeckler, I'll get those changes taken care of. It won't likely be until Saturday as I'm traveling this weekend, but they are on my to-do list. Any hints on why the test failed? I had this fail locally, but I thought it may have been a local thing. I couldn't figure out why this particular error was being triggered.
Comment #13
tstoecklerI think the reason for these errors is the problem I hinted at in the issue summary:
ContainerForm
extendsForumForm
in current 8.0.x, so it probably needs to be adapted in some way. It probably needs to split similarly intoContainerAddForm
andContainerEditForm
, which both extend aContainerFormBase
, which in turn extendsForumFormBase
. Sadly we cannot avoid duplicated code in this case, because of our inheritance chains, i.e. forContainerAddForm
we cannot extend bothContainerFormBase
andForumAddForm
, so we probably need to copy the relevant bits fromForumAddForm
. At least that's what seems to be the sanest solution that I've come up with, feel free to think of a better one. :-)Comment #14
larowlanIn which case we need a trait?
Comment #15
tstoecklerSure, I think that would make sense. I think this is just another proof that we should replace most of our endlessly long inheritance chains with traits, but there a lot of people in the Drupal community who will fight back against that. In this case, though, we have a concrete reason, so let's do it!
Comment #16
Michael Hodge Jr CreditAttribution: Michael Hodge Jr commentedAlright, so I was able to get this worked out in a way that reduces the duplicated code, but didn't require a trait in order to do so. The test was failing because of the save() method in the container class. The message being output wasn't what the test expected.
I also refactored the ForumAdd/Edit classes some more per comment #2 to reduce some of the duplicated code. I also split the Container into ContainerAdd and ContainerEdit as appropriate.
Let me know what you guys think of this patch.
Comment #17
Michael Hodge Jr CreditAttribution: Michael Hodge Jr commentedForgot a space between one of my functions. New patch and interdiff attached.
Comment #18
Michael Hodge Jr CreditAttribution: Michael Hodge Jr commentedComment #19
larowlanFYI the issue is #1976298: Move taxonomy_get_tree() and associated functions to Taxonomy storage, deprecate procedural wrappers. which is RTBC, so might need a re-roll if that goes in first.
Screenshots from manual testing
Comment #20
tstoecklerAwesome work @Michael Hodge Jr !!! Thanks for finishing this off!
Comment #21
alexpottComment #22
Michael Hodge Jr CreditAttribution: Michael Hodge Jr commentedHere is the rerolled patch
Comment #23
larowlanta
Comment #24
tim.plunkettWe don't use hyphens for form classes, please use underscores.
Why aren't these abstract? Also this just means yet another parent class. They could instead use the "template method pattern", like EntityStorageBase and BlockBase do, by declaring new abstract protected methods, calling those, and thereby forcing the subclasses to just implement their functionality without the need for overriding/parent::
Most importantly, I wonder if we're actually gaining anything here.
As I commented on #2324877-3: Split ShortcutSetForm into ShortcutSetAddForm and ShortcutSetEditForm:
Comment #25
tim.plunkettComment #26
tstoeckler@tim.plunkett: Search for *AddForm classes in core. This is a pre-existing pattern and we should employ it consistently. The fact that we haven't so far has various legacy reasons, but that doesn't mean it should stay that way.
Regarding new abstract methods are you thinking along the lines of
getDisplayMessage()
,getLogMessage()
, etc.? I think that would be a great idea. I did not suggest it because there is no such pattern for forms yet in core, but on the other hand, if we're touching all these files here, we might as well do it right.Comment #27
kim.pepperRe-roll of #22 plus a fix for #24 1)
Comment #29
acrosmanI'm at DrupalCon LA Sprint. I'll try to re-roll the last working version of the patch for this issue.
Comment #30
acrosmanI've rerolled the patch from #27
Comment #32
acrosmanAdded namespaces to a few calls to l() and re-rolled the patch.
Comment #33
mglamanMarking for review to kick off test bot for updated patch in #32
Comment #35
arskiainen CreditAttribution: arskiainen as a volunteer commentedRerolled patch from #32.
Comment #39
neetu morwani CreditAttribution: neetu morwani commentedComment #44
neetu morwani CreditAttribution: neetu morwani commentedComment #45
hoebekewim CreditAttribution: hoebekewim as a volunteer commentedComment #46
hoebekewim CreditAttribution: hoebekewim as a volunteer commentedUsed entityManager to retrieve the taxonomy items and vocabulary.
Passed an URL object instead of a link to Drupal::l().
This is part of a Drupal code sprint, i've noticed that some tests have failed. Work in progress.
Comment #47
MykolaBova CreditAttribution: MykolaBova as a volunteer commentedComment #49
hoebekewim CreditAttribution: hoebekewim as a volunteer commentedMissing conversions to \Drupal::l() and passing the Url object using routing instead of a direct link.
ForumForm extends from ForumFormBase now and the duplicate code has been removed from ForumForm.
Maybe ForumForm can be removed now ?
Comment #50
hoebekewim CreditAttribution: hoebekewim as a volunteer commentedComment #51
stefan.r CreditAttribution: stefan.r commentedLet's remove ForumForm as well, I don't think we don't need it anymore?
Comment #52
hoebekewim CreditAttribution: hoebekewim as a volunteer commentedRemove @todo comments and removal of ForumForm in favor of ForumFormBase.
Comment #53
stefan.r CreditAttribution: stefan.r commentedA few unrelated changes but those are fairly straightforward. I think this looks OK now, just needs a beta evaluation.
Comment #54
andypostComment #57
larowlanpinged maintainer to see if this is still possible or is now a BC break
Comment #58
naveenvalechaCould we deprecated the existing forms in 8.2/3.x and remove it in 9.x like here https://www.drupal.org/node/2428003#comment-11688399
Comment #59
alexpottYep we can't remove the classes in D8 but we can deprecate and use the new stuff.
Comment #60
catchJust discussed this with @xjm. https://www.drupal.org/core/d8-bc-policy wasn't 100% clear, but form classes are in the same category as controllers, hence @internal, hence we don't need a bc layer here at all.
If this is going to affect form alters at all we should have a change record though.
Comment #61
naveenvalechaThe patch in #52 does not apply anymore.
We don't need beta evaluation anymore for 8.3.x & 8.2.x
Comment #62
yogeshmpawarComment #63
yogeshmpawarHere is the rerolled the patch against 8.3.x
Comment #64
naveenvalechaMore cleanup, less weight patch :)
Comment #65
naveenvalechaComment #66
larowlanshould this be abstract?
Why did we remove the local variable?
Comment #67
naveenvalecha#66.1
yup we can make it abstract
#66.2
Reverted. This was in the rerolled patch above :)
More cleanup, less weight patch :)
Comment #68
naveenvalechaReplaced the deprecated functions.
Comment #69
larowlanThis is duplicated in the add and edit form, but both of them extend the base form. Could we move them into the parent and remove the duplication?
Comment #70
naveenvalechaRemoved the duplicated code to the ForumBase Abstract class.
Comment #71
andypostlooks good, the only thing is BC - this form class names can be used in contrib
that's makes me think about BC for contrib
Comment #72
naveenvalecha#71, AFAIK, This is not BC as per the bc-policy because the form classes and controllers are internal unless they are tagged with @api https://www.drupal.org/core/d8-bc-policy#controllers
// Naveen
Comment #73
larowlanI think this is ready, but over to alexpott to confirm the BC question/otherwise
Comment #74
andypostProper status
Comment #76
andypostComment #77
catchThe bc issue here seems fine.
One thing I thought of was deprecating the old classes deprecated for removal in 8.4.x - then if someone really is using them, it gives them a minor release cycle to update.
Comment #85
alexpottWe should deprecate the old classes instead of removing them. Our policy on these is best effort and leaving them in core but unused and deprecated seems fine to me - especially as the deprecation message is to extend the new abstract classes - which seem to have all the original functionality.
Comment #86
mradcliffeI added the Needs issue summary update as I think that there is still a Novice task for the issue to re-scope the issue based on @alexpott's note about deprecating the old class and adding the new ones.
Comment #93
quietone CreditAttribution: quietone at PreviousNext commentedForum is approved for removal. See #1898812: [policy] Deprecate forum module for removal in Drupal 11
This is now Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.
It will be moved to the contributed extension once the Drupal 11 branch is open.
Comment #95
quietone CreditAttribution: quietone at PreviousNext commented