Trigger Plugin from model - Joomla - php

I created a custom plugin for my joomla extension, it all works well while trying to trigger it from a template override (just for test).
But when I try to fire it from the extension model (the same code that works in the override) it doesn't trigger the event.
Is there anything specific that needs to be done to the extension to be able to trigger it from the model?
here is what I am using and works in the template override but doesn't work in the model
JPluginHelper::importPlugin('bookingnotification');
$dispatcher = JEventDispatcher::getInstance();
$dispatcher->trigger('onHelloWorld', array());
I am clueless

I found the answer to own my question.
For some reason if I am triggering the event from a template override I can specify only the plugin folder in the importPlugin, like below
JPluginHelper::importPlugin('bookingnotification');
But if I am triggering it from the model it will only work (or at least in my case) if I specify the the group and the plugin folders, like below
JPluginHelper::importPlugin('user','bookingnotification');
I hope this helps some else

Related

Add an element to a hook with a FrontController

I am currently developing a prestashop module where the user can add as many visual elements (an accordion) as he wishes. I finished the configuration of the back office with my own database, everything is ok on that side.
The problem comes from the fact that depending on the hook chosen by the user (displayHome or a custom hook) the visual element will be added to it.
During my testing phases, I managed to display the corresponding visual rendering on the displayHome hook, via this method in my main file :
public function hookDisplayHome($params)
{
$this->context->smarty->assign([
//...
]);
return $this->display(__FILE__, 'my_file.tpl');
}
The prestashop documentation for the FrontController explains how to configure it for visual rendering on a custom page, but nothing related to hooks.
I tried a similar process with the initContent() method but it doesn't seem to work.
I think that if() will be enough to assign the variables to different places according to the choice of the user. But if I can't just display it, I won't be able to think about it anyway.
How to interact with hooks via the FrontController ?

Is there a way to register hook NOT creating the module in PrestaShop?

I'm working on my own store, and I want to add some custom functionality. But this functionality is not something standalone, so I'd prefer to completely implemented via overriding controllers/classes and not to create a separate module for this.
But I have to use some hooks (for example - displayAdminProductsExtra to add new tab to admin product page, or actionProductAdd/actionProductUpdate to make some custom edits to DB). I know the way to use hooks from within the modules, but I cant find the way to do without creating my own module).
So the question - is there a way to do so?
Thanks in advance.
Hooks are only meant to be used with modules.
When Hook::exec() is called it will first check if a module is attached to this hook and stop otherwise.
Here is the related code:
// If no modules associated to hook_name or recompatible hook name, we stop the function
if (!$module_list = Hook::getHookModuleExecList($hook_name)) {
return '';
}

How to override prestashop's default front-office template and controller in module

I want to override prestashop's default front-office template and controller in my newly created module without modifying prestashop's internal code/structure.
Example :
I have created one module i.e. "mymodule" in /modules folder where I want use prestashop's address form (address.tpl).
see : http://demo-store.prestashop.com/en/address.
I want to enhance address form by providing some additional fields/functionality but without changing prestashop's core functionality.
So, How can I override its controller/themes/templates in my module? I have searched lot of about this on google but didn't found anything :(
Any help would be appreciated.
Modules can work like you ask only if there's an HOOK inside the template/controller that allow you to run your customized function. Look if you have a chance of hooking your module somewhere by watching on the list showed inside
backoffice > modules > position
the Address controllers hasn't got any Hook if i recall well, so you have 3 ways to edit its functionality:
Go for an (imho) horrible client-side modification, by an heavy usage of jquery/ajax call to perform the action you need. Place the code by using a module that only add your js script in the header by using the hookHeader() function. Since this hook it's always called in all the site you can exploit the missing hook in the address template.
add yourself an hook inside the Controller and the template by following this procedure: http://www.prestashop.com/forums/topic/218291-create-custom-and-new-hook-in-ps-15/
use the amazing override features of the prestashop framework to modify what you need in the Controller file placed inside your prestashop_root/override/controllers/front/AddressController.php and inside your /prestashop_root/themes/my_theme/address.tpl. this way you can ovverride any function of the Controller withouth loosing the original functionality and if you'll need to upgrade your installation you will just need to check for the function you changed in the overrided file just as you would do for your module.

CakePHP 1.3: Alaxos ACL Plugin not recognizing Pages Plugin

I have been developing with CakePHP and the Alaxos ACL plugin has helped in tremendously.
However, I am facing one issue I am not sure how to fix it?
I added a plugin named 'pages', but I cannot get ACL to see it so it is added to the list of allowed/denied actions.
If I access the plugin thru domain.com/pages/pages I get the following error
DbAcl::check() - Failed ARO/ACO node lookup in permissions check.
When I check thru the ACL plugin display, there is no reference to the pages controller and if I run the ACL build function, it simply says that there is nothing to add.
Is it because this controller is named pages and there is already a pages controller within Cake?
If it is how do I fix it? Is my only option, at this time, adding this manually to the Db? Should I go thru this plugin and rename pages to something else? or is there anything else I should be doing?
Thanks,
I see two things here. First like you suspect, having two classes in your application that share the same name is a bad idea. It will likely give you some problems in one way or another, with the wrong class being instantiated or whatever. As far as Cake does not use namespaces, this is not recommended.
Then, even if you change this name, there will be another problem if the controller you want to manage with ACL is the 'default' controller (a controller that has the same name as the plugin). There was an issue with the ACO nodes retrieval when the path contains twice the same name, which is the case for plugins default controllers.
controllers/Pages/Pages/index
So I decided to just skip the plugins default controllers from the controllers supported by the ACL plugin.
If you are the author of this plugin, you could rename it (because PagesController exists already), and move the actions in some other controller than the default controller.

How to override a user profile view,, in our own plugin, in elgg

I have created a new plugin named 'adv' in my elgg site.
And in this plugin iam listing the users.Which using the view from other elgg plugin 'profile
ie the page profile/views/default/profile/listing.php.
Now i need to set a link in the existing view of each user.So i have to edit the profile plugin , mainly the page profile/views/default/profile/listing.php
But how can i do this, without modifying elggs default plugin 'profile'.
I have tried a method that i have copied the folder 'profile' from profile/views/default/profile and put it in adv/views/default/.But it donot working.]
Is any solution for adding new link to the user view with editing other plugin, only editing our own plugin example 'adv'.
You'll need to override the profile/listing view, but only when Elgg is rendering your plugin's pages, not to interfere with other plugins that might want to use the core profile/listing view.
My approach to this problem is the following:
Create a new directory that will hold the views that you want to override.
In your case, I'd create the "adv/views/mod" directory within your_site_root/mod.
Add the view you'd like to override into this directory.
Again, your case, copy the profile/views/default/profile/listing.php to the following location: adv/views/mod/default/profile/listing.php
Make your modifications to the newly created view.
You can now safely modify the adv/views/mod/default/profile/listing.php file to your liking
Tell Elgg to use the special view when your plugin is rendering the page. This means you'll have to call the set_view_location(..) method either from your page_handler function, or the php files that are referenced by your page_handler and usually prepare the data for the views (like index.php or read.php, but I don't know your plugin's file hierarchy)
So in your case you'd call set_view_location('profile/listing', $CONFIG->pluginspath . 'adv/views/mod/'); either from your page_handler or from one of the above files.
Make sure that $CONFIG is present and available by referencing it (global $CONFIG).
Please check if "Use view filepath cache (recommended)", is disabled in the site administration. Because elgg uses hard view cache. Or delete the view_cache file from the data directory. And also make user your plugin is below the "Profile" in the plugin list.

Categories