Jump to content

Some action after a widget is removed


Go to solution Solved by ReyDev,

Recommended Posts

1 hour ago, Adriano Faria said:

Or do you really mean add/remove a widget from the widget containers (sidebar, top or bottom)?

This is exactly what I meant.

I am going to clean up something after removing the widget from the sidebar or main area

Edited by ReyDev
Link to comment
Share on other sites

6 hours ago, Adriano Faria said:

You have to extend \IPS\core\modules\front\system\widgets::saveOrder().

Thanks, but according to what I've read about widgets, the delete method is called before deleting the widget.
This method is used in the WYSIWYG Editor widget, for example
So what does this method really do?

/**
 * Before the widget is removed, we can do some clean up
 *
 * @return void
 */
public function delete()
{
   /* Does nothing by default but can be overridden */
}
Link to comment
Share on other sites

I'm not sure this is the approach you want to take. What would happen if your widget is used on 10 different pages? If you remove it from one of them this would change the setting for all other pages. You haven't said what this "clean up" is all about.

You should look into using the configuration() method in the widget. And/or deal with the settings in the ACP. Look at the relatedContent or stream widget in the core app to see how that's done.

If you look at the topContributors widget, the delete method is used to delete a custom language string that's part of the widget configuration.

Link to comment
Share on other sites

  • Solution
1 hour ago, Martin A. said:

I'm not sure this is the approach you want to take. What would happen if your widget is used on 10 different pages? If you remove it from one of them this would change the setting for all other pages. You haven't said what this "clean up" is all about.

You should look into using the configuration() method in the widget. And/or deal with the settings in the ACP. Look at the relatedContent or stream widget in the core app to see how that's done.

If you look at the topContributors widget, the delete method is used to delete a custom language string that's part of the widget configuration.

 

58 minutes ago, Daniel F said:

Why would you want to change a global setting when the widget is removed?
What are you trying to achieve?

I solved my problem in another way. But I think this can be useful.

When I add the widget, I add a value to the array that is stored in the settings. I do this when configuring the widget. (configuration() method)
Now I want to remove this value from the array I defined, when deleting the widget. (I thought the delete method would do that)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...