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

Allow all callables for extend view #2024

Merged
merged 1 commit into from
Oct 22, 2021
Merged

Allow all callables for extend view #2024

merged 1 commit into from
Oct 22, 2021

Conversation

zaxxo
Copy link

@zaxxo zaxxo commented Oct 20, 2021

This allows all callables (e.g. anonymous functions and not only global functions) to extend a view.

@lianglee
Copy link
Member

Thanks will merge it soon!

@lianglee lianglee merged commit aafc987 into opensource-socialnetwork:v6.x Oct 22, 2021
@lianglee
Copy link
Member

Allow all callables for extend view. We need to make sure hook and callbacks are function exists not is_callable because we need to unregister them and I am not sure if it is possible to unregister anonymous functions.

@zaxxo
Copy link
Author

zaxxo commented Oct 22, 2021

If you have a reference to the anonymous function then an unset is possible:

$fnc = fn($hook, $type, $return, $params) => 'foo';
ossn_add_hook('profile', 'edit:section', $fnc);
ossn_unset_hook('profile', 'edit:section', $fnc); // This is possible

But if you have no reference to the anonymous function then an unset is not possible:

ossn_add_hook('profile', 'edit:section', fn($hook, $type, $return, $params) => 'foo');
ossn_unset_hook('profile', 'edit:section', ???); // This is not possible

So if a developer needs to unregister an hook then he can't register the hook with an anonymous function.

@zaxxo zaxxo deleted the extend-view-callable branch October 22, 2021 08:05
lianglee added a commit that referenced this pull request Oct 22, 2021
@lianglee
Copy link
Member

Thanks for sharing , I think I will leave as it is and let others developers use the anonymous functions in the hooks if they want. Added you to the contributors list now.

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

Successfully merging this pull request may close these issues.

None yet

2 participants