Overwriting plugin templates in theme

221 views
Skip to first unread message

testingp...@gmail.com

unread,
Mar 15, 2016, 9:11:51 AM3/15/16
to ICA-AtoM Users
Hi,

is it possible to overwrite plugin templates from inside a new theme plugin?
I am writing a new theme (for atom 2.2.1) and I want to change for example the "Edit accession record" template (/accession/add) without changing /plugins/qtAccessionPlugin/modules/accession/templates/editSuccess.php so the original theme keeps unchanged.

Regards,
Tom

José Raddaoui

unread,
Mar 15, 2016, 1:57:51 PM3/15/16
to ICA-AtoM Users, testingp...@gmail.com
Hi Tom, great question!

I could not find a quick and proper solution for that some time ago and, as keeping the original theme unchanged was not a requirement, I ended modifying the template in the plugin directly.

The global templates and the normal modules are overwritten in the theme plugin configuration class, for example:


Maybe you can find something to do the same with the plugins or plugins modules. Please, if you find a solution I will love to hear it.

Regards and sorry I can't be more helpful.

Dan Gillean

unread,
Mar 15, 2016, 2:01:24 PM3/15/16
to ICA-AtoM Users
Hi Tom,

In case it is helpful, we have recently created a basic guide on developing a custom theme in our documentation, here:

This may be moved in the near future - we've also created a new Developer's Guide in the documentation to document new API endpoints that will be included in the AtoM 2.3 release - I think it would make more sense to expand the developer's guide and move it there. For now, the above link will take you there, and hopefully there will be a few helpful tips on how to create a custom theme plugin, if you're not already familiiar with Symfony plugin development.


Cheers,


Dan Gillean, MAS, MLIS
AtoM Program Manager
Artefactual Systems, Inc.
604-527-2056
@accesstomemory

--
You received this message because you are subscribed to the Google Groups "ICA-AtoM Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ica-atom-user...@googlegroups.com.
To post to this group, send email to ica-ato...@googlegroups.com.
Visit this group at https://groups.google.com/group/ica-atom-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ica-atom-users/6cb57163-8687-47ec-9708-b19e9e49a8bc%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

testingp...@gmail.com

unread,
Mar 16, 2016, 10:18:02 AM3/16/16
to ICA-AtoM Users
Thank you for your answers.

After thinking a bit about this issue again I think it won't make sense to modify the entire structure/layout of AtoM as part of a theme plugin.
Sure it would be nice if it would be possible to switch back to the original theme but if someone changes almost everything this will most likely never happen.
I also think that another new similar theme suitable for the new structure isn't something someone will need.

Because the original theme won't be used I will do it like José and modify the templates directly.
Could it be that I misunderstood the term "Theme"?

Regards,
Tom

David

unread,
Apr 12, 2016, 11:09:51 AM4/12/16
to ICA-AtoM Users, testingp...@gmail.com
Hi,

I am working on a project to include AtoM 2.3 into another existing system so I will change the whole look and feel therefore I will also change the plugins at project level.

Inside sfProjectConfiguration there is a function setPluginPath($plugin, $path) [1] to set the location of a particular plugin.
This function can be used to override the plugins:
  1. Create a new folder 'plugins' inside the theme plugin
  2. Copy/paste all plugins
  3. Change the theme plugin configuraiton file: Set the new location for all plugins but not for the theme plugin inside initialize() [2]
  4. Clear the cache / restart php5-fpm. (this can also be necessary after switching back to the original theme)
It seems to work but I have only tested to override one or two templates yet so I can not guarantee if this can be done without getting into troubles.
Because I am not a PHP dev it would be nice if someone could check this too.

Regards,
David



[1] https://github.com/artefactual/atom/blob/qa/2.3.x/vendor/symfony/lib/config/sfProjectConfiguration.class.php#L505

[2] atom/plugins/pluginName/config/pluginNameConfiguration.class.php
public function initialize()
{
    foreach ($this->configuration->getPlugins() as $plugin)
    {
        if (strcmp($plugin, $this->name) !== 0)
        {
            $path = $this->rootDir . '/plugins/' . $plugin;
            $this->configuration->setPluginPath($plugin, $path);
        }
    }
     

    $this->dispatcher->connect('context.load_factories', array($this, 'contextLoadFactories'));

    $decoratorDirs = sfConfig::get('sf_decorator_dirs');
    $decoratorDirs[] = $this->rootDir.'/templates';
    sfConfig::set('sf_decorator_dirs', $decoratorDirs);
   
    $moduleDirs = sfConfig::get('sf_module_dirs');
    $moduleDirs[$this->rootDir.'/modules'] = false;
    sfConfig::set('sf_module_dirs', $moduleDirs);

raddao...@gmail.com

unread,
Apr 12, 2016, 12:32:19 PM4/12/16
to ICA-AtoM Users, testingp...@gmail.com
Thanks for sharing David, that looks really promising!

There may be some gotchas in the application where the plugin paths are referenced without using sfConfig and other issues, but it looks like the way to go if it's needed. You could also overwrite only the plugins you need to customize to avoid duplications.

I'll give it a try and report back if I find more information.

Best regards.

David

unread,
Apr 26, 2016, 7:29:38 AM4/26/16
to ICA-AtoM Users, testingp...@gmail.com, raddao...@gmail.com
Hi,

I think I found such a problem using this approach.
I enabled the new plugin (with plugins copied inside plugins/themePlugin/plugins).
Afterwards I could not visit Admin->Plugins/Themes any more.

Fatal error: Cannot redeclare class sfEacPluginConfiguration in /usr/share/nginx/atom/plugins/themePlugin/plugins/sfEacPlugin/config/sfEacPluginConfiguration.class.php on line 0
https://github.com/artefactual/atom/blob/qa/2.3.x/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/pluginsAction.class.php#L56
https://github.com/artefactual/atom/blob/qa/2.3.x/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/themesAction.class.php#L55

Possible fix that seems to work:
if (!class_exists($name)) {
    require_once $classPath;
}

But I don't get it why this is required. (it isn't for dominionPlugin) Doesn't require_once prevent the "cannot redeclare class" error?
The "on line 0" part also confuses me.


Something else I have noticed:
https://github.com/artefactual/atom/blob/qa/2.3.x/plugins/sfPluginAdminPlugin/modules/sfPluginAdminPlugin/actions/pluginsAction.class.php#L43-L46
If I add error_log("unset " . $name . ": " . $pluginPaths[$name]); before unset I get following output:
"PHP message: unset sfPropelPlugin: "
So there is no path for this plugin at this point. This is because the sfPropelPlugin is not inside the plugins/ directory but inside vendor/symfony/lib/plugins/sfPropelPlugin.
I am pretty sure that this can lead to a problem so I have copied this dir also inside plugins/themePlugin/plugins.

Regards,
David

David

unread,
May 5, 2016, 8:12:12 AM5/5/16
to ICA-AtoM Users, testingp...@gmail.com, raddao...@gmail.com
Hi again,

Is it possible to override application configuration files like '/apps/qubit/config/view.yml' inside a theme plugin?
It is not sufficient to only copy the files to themePlugin/config/.
I've also tried to set 'sf_app_config_dir' inside themePluginConfiguration.class.php: sfConfig::set('sf_app_config_dir', $this->rootDir.'/config');
Any suggestions?

Regards,
David

José Raddaoui

unread,
Jun 1, 2021, 12:23:47 PM6/1/21
to AtoM Users
Hi there,

It has been five years but, if someone come across this thread, we finally found a solution to the issue:


In order to overwrite a controller or view from another plugin module, you'll need to create the plugin modules folders inside the theme modules folder (not the entire plugin, just the modules), and it will work the same way as with the main application modules.

David, if you're still around and it's still relevant, what would be the use case of changing the config that way, it usually works the other way around.

Best,
Radda.
Reply all
Reply to author
Forward
0 new messages