Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gaurav.kapoor created an issue. See original summary.

gaurav.kapoor’s picture

Now since the parent function is fetching required value by $taxonomy_term = $this->entity. It shouldn't be sent as an argument.

pritish.kumar’s picture

Status: Needs review » Reviewed & tested by the community

Tried and tested. $taxonomy_term is redundant

pritish.kumar’s picture

Assigned: gaurav.kapoor » Unassigned
alexpott’s picture

Category: Bug report » Task
Status: Reviewed & tested by the community » Needs work

Then

    $taxonomy_term = $this->entity;

Should be removed too because this is not needed either.

Changing to a task because nothing is broken.

alexpott’s picture

Also \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.

gaurav.kapoor’s picture

klausi’s picture

Status: Needs review » Needs work
+++ b/core/modules/forum/src/Form/ContainerForm.php
@@ -22,7 +22,7 @@ class ContainerForm extends ForumForm {
     $taxonomy_term = $this->entity;
     // Build the bulk of the form from the parent forum form.
-    $form = parent::form($form, $form_state, $taxonomy_term);
+    $form = parent::form($form, $form_state);

$taxonomy_term is now unused and should be removed here as well.

gaurav.kapoor’s picture

gaurav.kapoor’s picture

-    $taxonomy_term = $this->entity;
-    // Build the bulk of the form from the parent taxonomy term form.
-    $form = parent::form($form, $form_state, $taxonomy_term);
+    // Build the bulk of the form.
+    $form = parent::form($form, $form_state);

What shall we do for this comment . "Build the bulk form...."? @alexpott and @klausi

dbjpanda’s picture

Submitted a patch

dbjpanda’s picture

@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'));

The last submitted patch, 7: drupal-extra-arguments-sent-to-form-function-2858667-7.patch, failed testing.

The last submitted patch, 9: drupal-extra-arguments-sent-to-form-function-2858667-9.patch, failed testing.

dbjpanda’s picture

 public function form(array $form, FormStateInterface $form_state) {
    $taxonomy_term = $this->entity;
    // Build the bulk of the form from the parent taxonomy term form.
    $form = parent::form($form, $form_state, $taxonomy_term);

    // Set the title and description of the name field.
    $form['name']['#title'] = $this->t('Forum name');
    $form['name']['#description'] = $this->t('Short but meaningful name for this collection of threaded discussions.');

    // Change the description.
    $form['description']['#description'] = $this->t('Description and guidelines for discussions within this forum.');

    // Re-use the weight field.
    $form['weight'] = $form['relations']['weight'];

    // Remove the remaining relations fields.
    unset($form['relations']);

    // Our parent field is different to the taxonomy term.
    $form['parent']['#tree'] = TRUE;
    $form['parent'][0] = $this->forumParentSelect($taxonomy_term->id(), $this->t('Parent'));

    $form['#theme_wrappers'] = array('form__forum');
    $this->forumFormType = $this->t('forum');
    return $form;
  }

As i can see $taxonomy_term is a variable which stores variable enitity . Then how is it possible to call a function using variable ??

gaurav.kapoor’s picture

Status: Needs review » Reviewed & tested by the community

Parent 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.

dbjpanda’s picture

Status: Reviewed & tested by the community » Needs review

@gaurav.kapoor I am telling about id() function forumParentSelect($taxonomy_term->id(), $this->t('Parent'));

gaurav.kapoor’s picture

In containerform.php , there is this function call

$form = parent::form($form, $form_state, $taxonomy_term);

But if we check defination of its parent class form function it is like this.

public function form(array $form, FormStateInterface $form_state) {

Parent function is getting term taxonomy_term in this way. So it shouldn't be send as argument.

$taxonomy_term = $this->entity;

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.

gaurav.kapoor’s picture

-    $form = parent::form($form, $form_state, $taxonomy_term);
+    $form = parent::form($form, $form_state);

Just change it back , then this will be solved.

gaurav.kapoor’s picture

Status: Needs review » Needs work
gaurav.kapoor’s picture

Status: Needs work » Needs review
FileSize
1.37 KB
vidhatanand’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #11 solves the issue for me here.

dbjpanda’s picture

@vidhatanand @gaurav.kapoor thanks for the review. Patch #11 need to be ported.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/forum/src/Form/ForumForm.php
@@ -31,7 +31,7 @@ class ForumForm extends TermForm {
     $taxonomy_term = $this->entity;

We should remove this local variable as well since it is only used in one place. We can change that to read the property directly.

gaurav.kapoor’s picture

Status: Needs work » Needs review
FileSize
1.92 KB
982 bytes

Status: Needs review » Needs work

The last submitted patch, 25: drupal-extra-arguments-2858667-25.patch, failed testing.

gaurav.kapoor’s picture

Status: Needs work » Reviewed & tested by the community

#11 solves the issue , $taxonomy_term is required in ForumForm.php.

lauriii’s picture

Status: Reviewed & tested by the community » Needs review

It 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.

gaurav.kapoor’s picture

But i did it RTBC becuase of Patch #11 which fixes this issue.

lauriii’s picture

I see. :)

$taxonomy_term is required in ForumForm.php.

Could you then elaborate why is $taxonomy_term required in ForumForm?

gaurav.kapoor’s picture

I 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.

lauriii’s picture

There was unrelated random fail on #25. Currently the patch is green. So for anyone reviewing this issue, patch on #25 is reviewable.

gaurav.kapoor’s picture

@lauri : So #25 solves the problem you raised in #24 , can you confirm that and review the patch.

yogeshmpawar’s picture

#25 patch is working as expected. green signal to this patch

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Looks good!

lauriii’s picture

Status: Reviewed & tested by the community » Fixed

This 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!

  • lauriii committed 6434b39 on 8.4.x
    Issue #2858667 by gaurav.kapoor, dbjpanda: Extra arguments sent to a...
lauriii’s picture

Sorry 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.

dbjpanda’s picture

<?php
class Foo
{
protected $entity  ;
    function id()
    {
        return "do something" ;
    }
}

class Bar extends Foo {

     function test()
     {
         return $this->entity->id();
     }

}

$obj = new Bar();
$obj->test();

I 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.

$form['parent'][0] = $this->forumParentSelect($this->entity->id(), $this->t('Parent'));
 

Kindly correct me if i am wrong.

dbjpanda’s picture

Status: Fixed » Needs review
lauriii’s picture

Status: Needs review » Fixed

@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.

dbjpanda’s picture

$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 "

lauriii’s picture

@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?

dbjpanda’s picture

@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.

klausi’s picture

@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.

  • lauriii committed e43a961 on 8.4.x
    Revert "Issue #2858667 by gaurav.kapoor, dbjpanda: Extra arguments sent...
lauriii’s picture

Status: Fixed » Needs work

I 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!

dbjpanda’s picture

@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.

klausi’s picture

@dbjpanda: for entity forms the entity is initialized in HtmlEntityFormController::getFormObject().

lauriii’s picture

@dbjpanda: the remaining $taxonomy_term parameter is set on line 88 of TermForm

gaurav.kapoor’s picture

Status: Needs work » Needs review
FileSize
2.36 KB
358 bytes
klausi’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks!

dbjpanda’s picture

Reviewed and tested. working well. Now its perfect. Thanks.

lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for being persistent on this issue! Committed 260b823 and pushed to 8.4.x.

  • lauriii committed 260b823 on 8.4.x
    Issue #2858667 by gaurav.kapoor, dbjpanda, klausi: Extra arguments sent...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Anonymous’s picture

I think #39 , #44 and #48 never got into consideration , because of that there can be exception related to method override.