Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in method removeButton: Undefined variable: name #180

Closed
franciscocorrales opened this issue Oct 13, 2016 · 3 comments
Closed

Error in method removeButton: Undefined variable: name #180

franciscocorrales opened this issue Oct 13, 2016 · 3 comments
Labels

Comments

@franciscocorrales
Copy link

franciscocorrales commented Oct 13, 2016

This function, in src/PanelTraits/Buttons.php:

public function removeButton($name)
{
    $this->buttons->reject(function ($button){
        return $button->name == $name;
    });
}

Gives me the error:

ErrorException in Buttons.php line 80:
Undefined variable: name

Note: If I try with removeButtonFromStack I get the same error.

If I try to edit the line with:
$this->buttons->reject(function ($button) use($name) {
I don't get the error, but the button is not removed!.

This is my code:

 $this->crud->removeButton('preview');
 $this->crud->removeButton('update');
 $this->crud->removeButton('delete');

Background: what I am trying to achieve, is to stop showing the Actions column empty in the list view, when there's no action (button, I denied most access) there. Also, this column always gets printed, even if there are no buttons (I run this to hard reset the buttons $this->crud->buttons = collect();).

@tabacitu tabacitu added the Bug label Oct 17, 2016
@tabacitu
Copy link
Member

Hi @franciscocorrales ,

This is very weird. I tried it myself and $this->crud->removeButton('delete'); (preview, update, revisions, etc) works perfectly for me. And it shouldn't throw any errors there, $name is definitely defined, it's one of the parameters. Are you sure you haven't called $this->crud->removeButton() (without parameters) anywhere before that?

One bug, though, was that if I removed all buttons from the line stack, it was still showing. I fixed that in 3.1.31. If you've overwritten the list.blade.php file you need to also make the changes I made to it here.

Also, I've added two new methods:

  • $this->crud->removeAllButtons();
  • $this->crud->removeAllButtonsFromStack('line');

Please run a composer update and tell me if this fixes it.

Cheers!

@tabacitu
Copy link
Member

Oh, I just re-read your answer. Yes, it's possible that was a first draft of the function, but it's long been fixed - $name is there and I just checked on a second machine, different project: it works :-)

It's something that a composer update will definitely fix. If you could confirm, that would be great.

Cheers!

P.S. I'll go ahead and close this issue so we don't clog the section. Feel free to open it again if you encounter problems or comment if you have follow-ups.

@franciscocorrales
Copy link
Author

Confirmed.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants