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.
In file /core/modules/forum/src/Form/ContainerForm.php , a function parent::form is called with extra argument $taxonomy_term. In the definition of that form function it accepts only 2 arguments , $form and $form_state but no $taxonomy_term.
Comment | File | Size | Author |
---|---|---|---|
#51 | interdiff-25-51.txt | 358 bytes | gaurav.kapoor |
#51 | drupal-extra-arguments-2858667-51.patch | 2.36 KB | gaurav.kapoor |
#25 | interdiff-21-25.txt | 982 bytes | gaurav.kapoor |
#25 | drupal-extra-arguments-2858667-25.patch | 1.92 KB | gaurav.kapoor |
#21 | drupal-extra-arguments-2858667-21.patch | 1.37 KB | gaurav.kapoor |
Comments
Comment #2
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedNow since the parent function is fetching required value by $taxonomy_term = $this->entity. It shouldn't be sent as an argument.
Comment #3
pritish.kumar CreditAttribution: pritish.kumar commentedTried and tested. $taxonomy_term is redundant
Comment #4
pritish.kumar CreditAttribution: pritish.kumar commentedComment #5
alexpottThen
Should be removed too because this is not needed either.
Changing to a task because nothing is broken.
Comment #6
alexpottAlso
\Drupal\forum\Form\ForumForm::form()
does the same thing and should be fixed as it is part of the same scope - ie. it one of methods this is overriding and calling.Comment #7
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #8
klausi$taxonomy_term is now unused and should be removed here as well.
Comment #9
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #10
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedWhat shall we do for this comment . "Build the bulk form...."? @alexpott and @klausi
Comment #11
dbjpanda CreditAttribution: dbjpanda at Google Summer of Code commentedSubmitted a patch
Comment #12
dbjpanda CreditAttribution: dbjpanda at Google Summer of Code commented@gaurav.kapoor Why did you remove $taxonomy_term = $this->entity; from line# 32 of ForumForm.php
id() has been called by $taxonomy_term in line #51
$form['parent'][0] = $this->forumParentSelect($taxonomy_term->id(), $this->t('Parent'));
Comment #15
dbjpanda CreditAttribution: dbjpanda at Google Summer of Code commentedAs i can see $taxonomy_term is a variable which stores variable enitity . Then how is it possible to call a function using variable ??
Comment #16
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedParent function form(array $form, FormStateInterface $form_state) accepts only 2 arguments , it was being called with an extra argument $taxonomy_term. #11 fixes the issue.
Comment #17
dbjpanda CreditAttribution: dbjpanda at Google Summer of Code commented@gaurav.kapoor I am telling about id() function
forumParentSelect($taxonomy_term->id(), $this->t('Parent'));
Comment #18
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedIn containerform.php , there is this function call
But if we check defination of its parent class form function it is like this.
Parent function is getting term taxonomy_term in this way. So it shouldn't be send as argument.
And since $taxonomy_term is not to be sent as argument , it defination in containerform.php shall also be removed. Ignore my patch in #9 and #7.
Comment #19
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedJust change it back , then this will be solved.
Comment #20
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #21
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #22
vidhatanand CreditAttribution: vidhatanand at OpenSense Labs commentedPatch in #11 solves the issue for me here.
Comment #23
dbjpanda CreditAttribution: dbjpanda at Google Summer of Code commented@vidhatanand @gaurav.kapoor thanks for the review. Patch #11 need to be ported.
Comment #24
lauriiiWe should remove this local variable as well since it is only used in one place. We can change that to read the property directly.
Comment #25
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #27
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commented#11 solves the issue , $taxonomy_term is required in ForumForm.php.
Comment #28
lauriiiIt is generally not a good practice to set the status to reviewed & tested by the community when the latest patch on the issue is one's own patch. You can find more information about issue status here.
Comment #29
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedBut i did it RTBC becuase of Patch #11 which fixes this issue.
Comment #30
lauriiiI see. :)
Could you then elaborate why is
$taxonomy_term
required inForumForm
?Comment #31
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedI replaced usage of $taxonomy_term with $this->entity in ForumForm.php , but that led to test failures in #25. But in #11 and #21 we are using $taxonomy_term and it passes all the test cases. So it is required by file ForumForm.php.
Comment #32
lauriiiThere was unrelated random fail on #25. Currently the patch is green. So for anyone reviewing this issue, patch on #25 is reviewable.
Comment #33
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commented@lauri : So #25 solves the problem you raised in #24 , can you confirm that and review the patch.
Comment #34
yogeshmpawar#25 patch is working as expected. green signal to this patch
Comment #35
klausiLooks good!
Comment #36
lauriiiThis clean up looks good. However, while testing this I found some more issues on these forms so I decided to create a follow-up issue where can fix them: #2861022: ForumForm and ContainerForm forms are rendered using wrong texts.
I removed on the commit the change for the documentation since it is out of scope.
Committed 15ae76d and pushed to 8.4.x. Thanks!
Comment #38
lauriiiSorry for the confusion. I pushed a commit with a wrong commit message. I reverted that commit and pushed a new commit 6434b39with the correct commit message.
Comment #39
dbjpanda CreditAttribution: dbjpanda at Google Summer of Code commentedI am getting error "Call to a member function id() on null " .
And here i can see the same thing. $entity is a protected variable then how can we call a function id() without using object.
Kindly correct me if i am wrong.
Comment #40
dbjpanda CreditAttribution: dbjpanda commentedComment #41
lauriii@dbjpanda could you provide more specific steps how to reproduce the bug you are describing? I've tried to test this manually and I couldn't reproduce this. I'm setting this back to fixed since the change committed haven't changed visibilities one way or another.
What you are describing should work, as long as
$this->entity
is set and has public id method. Properties declared protected can be accessed within the class itself and by inheriting classes.Comment #42
dbjpanda CreditAttribution: dbjpanda at Google Summer of Code commented$this->entity->id()
Entity is a a protected member variable which is null in super parent class. Then how can a function i.e id() be called using a null variable. An object is required to call a function.
$this->variable->function()
returns an error " Call to a member function() on null "Comment #43
lauriii@dbjpanda Unfortunately, I am still unable to reproduce the bug you are describing here. Would you mind opening a new issue with the specific steps you've taken so that I can reproduce the bug?
Comment #44
dbjpanda CreditAttribution: dbjpanda commented@lauriii Though I have not tested it or reproduced the bug. I am asking about a general OOP concept which has been implemented here. Is it possible to call a function i.e id() using a null variable i.e entity.
Comment #45
klausi@dbjpanda: we just assume that $this->entity has been populated previously in the constructor or other method. If $this->entity is not set then it is totally fine to throw a PHP fatal error because something else is completely broken.
Comment #47
lauriiiI reverted the commit since @xjm pointed out that
Drupal\taxonomy\TermForm
is still passing the term to the form builder.@dbjpanda We use these issue threads only for resolving bugs, so I would suggest posting your question on a resource like stack exchange or the forums. Thanks for your interest in Drupal!
Comment #48
dbjpanda CreditAttribution: dbjpanda at Google Summer of Code commented@klausi Thanks. Perfect reply for my confusion. To call
id()
, $entity must be populated with an object. But i could not find any initialization of $entity in all of its parents class as well as child class. So do we need to initialize $entity with an object ?@laurii Could you please post the comment or issue no where xjm pointed out regarding the TermForm.
Comment #49
klausi@dbjpanda: for entity forms the entity is initialized in HtmlEntityFormController::getFormObject().
Comment #50
lauriii@dbjpanda: the remaining $taxonomy_term parameter is set on line 88 of TermForm
Comment #51
gaurav.kapoor CreditAttribution: gaurav.kapoor at OpenSense Labs commentedComment #52
klausiLooks good, thanks!
Comment #53
dbjpanda CreditAttribution: dbjpanda at Google Summer of Code commentedReviewed and tested. working well. Now its perfect. Thanks.
Comment #54
lauriiiThank you for being persistent on this issue! Committed 260b823 and pushed to 8.4.x.
Comment #57
Anonymous (not verified) CreditAttribution: Anonymous commentedI think #39 , #44 and #48 never got into consideration , because of that there can be exception related to method override.