how to customise Drupal's ImageZoom module - image

I'm using version 7.x-2.0-beta2
Included in the module is imagezoom.api.php
From what I understand; this is the file you apply any customisations to the image zoom functionality.
I assume you have to copy this file into your own site specific templates directory to protect it from being overwritten during any module update.
So the original is in sites/all/modules/imagezoom/imagezoom.api.php
I have taken a copy and moved it to sites/all/themes/[my_site_name]/templates/system/imagezoom.api.php
But the changes I make to this file are not reflected on the site.
(I have tried the changes in both path locations)
The function within this file is simply:
function hook_imagezoom_settings_alter(&$settings, $context) {
// Change the border color to red
$settings['borderColour'] = '#f00';
$settings['responsive'] = TRUE;
}
Can anyone tell me where this file has to be placed in order for the module to pay attention to it ?

You need to create a custom module and then simply create a function in the mymodule.module file which replaces the hook function, like this:
function mymodule_imagezoom_settings_alter(&$settings, $context) {
// Change the border color to red
$settings['borderColour'] = '#f00';
$settings['responsive'] = TRUE;
}
Replace whatever you want from the function above, clear your caches and you should be good to go.
In the link I provided above, look deeper at the "Implementing your own hook" section if you are still having trouble.
Once you have the hook working, you can use the dpm function to view the current values that the page can see. The devel module needs to be on for this to work. In your case, you probably want to do this:
dpm($settings);
and modify the values from there.

Related

Firefox extension: share state

I have a Firefox overlay extension with a tree in a sidebar.
How can I keep the tree state synchronized in several windows?
For example in first window added new item in tree, how update tree in other windows?
If somebody can show minimal code for it (with use code modules, observers, broadcasters or something else), please help.
I read similar question, but it did not help:
Firefox extension - Share common state between two or more windows
The answer in the question you reference is good, but short on explanation. You should read the references to which it links. I have duplicated those links here.
One way to keep state information outside of a window context is to use JavaScript code modules (JSM). The section Sharing objects using code modules talks briefly about doing this. Once you have set up your JSM to share the data, it is merely a matter of informing each window that a change has been made and it should update the displayed state. This is easily accomplished by using an event which you define. All of the sidebars listen for a particular event in their window. Then there is one function in the JSM which runs through all the windows signalling them that they need to update.
The code to signal could look something like:
Components.utils.import("resource://gre/modules/Services.jsm");
function forEachOpenWindow(todo) {
// Apply a function to all open browser windows
var windows = Services.wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
todo(windows.getNext().QueryInterface(Components.interfaces.nsIDOMWindow));
}
}
function signalUpdateNeeded(window){
let event = window.document.createEvent("Event");
event.initEvent("myExtensionName-UpdateAvailable",false,false);
window.dispatchEvent(event);
}
function sendUpdateAvailableToAllWindows(){
forEachOpenWindow(signalUpdateNeeded);
}
Then in the code for the sidebar:
//This imports your JSM, it does not need the .jsm extension, you can use
// whatever extension you want.
Components.utils.import("chrome://MyExtension/content/moduleName.jsm");
window.addEventListener("myExtensionName-UpdateAvailable",
updateDataFromModule, false);
//Instead you may need the following (or another way to get to the
// top window). What is actually needed will depend on the context in
// which your sidebar code is running. You should see below for code to
// access the main browser window from within a sidebar.
//window.top.addEventListener("myExtensionName-UpdateAvailable",
// updateDataFromModule, false);
function updateDataFromModule(){
//Whatever it is you need to do here.
mylocalVariable = myExtensionModule.dataStructure.whatever;
}
Refactoring the first code section above so that it looks like it is in a module that uses one variable to reduce namespace clutter. The code for the module could be something like:
var EXPORTED_SYMBOLS = [ "myExtensionModule" ];
Components.utils.import("resource://gre/modules/Services.jsm");
var myExtensionModule = {
dataStructure: {
whatever: true,
you: 1,
want: ["here.", "It", "is", "your", "data."]
};
forEachOpenWindow: function(todo){
// Apply a function to all open browser windows
var windows = Services.wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
todo(windows.getNext()
.QueryInterface(Components.interfaces.nsIDOMWindow));
}
},
signalUpdateNeeded: function(window){
let event = window.document.createEvent("Event");
event.initEvent("myExtensionName-UpdateAvailable",false,false);
window.dispatchEvent(event);
},
sendUpdateAvailableToAllWindows: function(){
this.forEachOpenWindow(this.signalUpdateNeeded);
}
}
I have not actually tested this, so there may be some errors.
Having either your sidebar code access the main browser window, or the JSM code find which sidebar your code is in (in order to send or listen fro events) may be a bit more complicated than you think. You should see Working with windows in chrome code. Specifically, Accessing the elements of the top-level document from a child window. That section provides the following code to access the main browser window from within a sidebar:
var mainWindow = window
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);
An alternative is for your JSM to keep a reference to an object in the data structure on which all of the sidebars place listeners. This could be an object which it creates. If you do use this method and choose to use a window, then you need to make sure that handle releasing the reference if the window is closed. If you don't you could end up with a memory leak.

How to change load layout in Joomla view?

By default parent::display($tpl); loads components/com_my_component/views/my_component/tmpl/default.php, but in some cases i need to load other php file which is in the same folder near default.php (for example components/com_my_component/views/my_component/tmpl/lol.php). How to do this from view.html.php.
P.S.
Tried load loadTemplate and setLayout methods with no luck.
Solved the problem by myself. Need to use the method setLayout and pay attention to the input syntax
$this->setLayout('dafault:lol');
parent::display($tpl);
By default, joomla looks for the layout keyword in the URL to decide which layout to display. If this variable is empty or not present then the tmpl/default.php layout will be loaded.
By editting your view.html.php file you can set the default layout by using the JView API, e.g. $this->setLayout('lol') will make the URL example.com/yourview equivalent to example.com/yourview?layout=lol.
However, this change alone will result in Joomla overriding it's default behaviour so that the layout request will be ignored. This means that the request example.com/yourview?layout=lmao will also display example.com/yourview = example.com/yourview?layout=lol
You can solve this easily by adding a condition around the setLayout function so that only if the layout keyword is not present then you will set the default layout to lol, e.g.
<?php
# ...
function display($tpl = null) {
# ...
# Edit : Set the default layout to 'lol'
$layout = JRequest::getWord('layout', '');
if (empty($layout)) $this->setLayout("lol");
// Display the view
parent::display($tpl);
}
# ...
I keep coming back to this and I've yet to find a satisfying solution.
What does work, from J1.5 right up to J3.4, for me has always been to set the $tpl variable in view.html.php
If $tpl is empty or "" then tmpl/default.php is displayed by default.
If you change $tpl to a string, e.g. $tpl="stacker" then it will look for and display tmpl/default_stacker.php
I've seen various differing theories on changing it earlier in the MVC so that it doesn't need the default_ pretext. e.g. tmpl/stacker.php
None have worked for me.

Magento layout basics

Im going through a version of No-frills Magento Layout (perhaps 4-5 months old) and am basically stuck right in the beginning.
In Indexcontroller, in the index action, I create a new block object.
public function indexAction()
{
//$this->loadLayout();
$block = new Mage_Core_Block_Template();
$block->setTemplate('helloworld.phtml');
//print_r($block->getTemplateFile());
echo $block->toHtml();
//$this->renderLayout();
I should then create a template file, namely helloworld.phtml and place it in the appropriate directory. I'm used to using a layout file to do this, but I am going through the book and am simply not able to render the file.
I have placed the phtml file in the following locations :
.../app/design/frontend/default/default/template
.../app/design/frontend/base/default/template
which is also the output of
print_r($block->getTemplateFile());
Im obviously missing something here. any chance someone can point it out?
cheers
Based on the comments above, I'd jump directly to to PHP file for the Mage_Core_Block_Template class
app/code/core/Mage/Core/Block/Template.php
Look for the include line and add some debugging that var_dumps whatever file Magento is trying to include OR add some debugging around the conditionals to determine why this isn't getting called.

Joomla: How to change template on a specific article

Is there a way to change the template on a specific article only?
Note that it should work without linking the article to any menu.
If you want the template override not to depend on the menu position than the standard joomla way of assigning a different template to a menu will not work. You will need to get your hands dirty and write some custom code. You will need to use the article_id as a trigger for template switch.
I did something like that at work but don't remember now how exactly this is achieved. I will post my code here as soon as I locate it.
EDIT: Found the code :)
You need to edit the file /includes/application.php, specifically the getTemplate() method. At the end of this method, just before:
// Fallback template
if (!file_exists(JPATH_THEMES.DS.$template.DS.'index.php')) {
$template = 'rhuk_milkyway';
}
you can add your condition for applying a custom template, like so:
//CUSTOM TEMPLATE FOR THE ARTICLE 13
if (JRequest::getVar('id')=='13' && JRequest::getVar('option')=='com_content') {
$template = $custom_template_name;
}
This will apply the custom template which name is inside the $custom_template_name to article with id=13. You can also use it to apply a different template to components, like I did with simplecaddy:
//TEMPLATE FOR SIMPLECADDY
if (JRequest::getVar('option')=='com_caddy'){
$template = 'shop';
}
You should really try to stay away from hard coding anything in to the template if it can be avoided. Not sure why you would specify that the article not be linked from a menu. The easiest way to accomplish this without having to write and code is to create a new menu, then add a menu item that links to the article you want to specify the template for. You don't have to put the menu in a module anywhere so it will never show up on the site, but it will show up in the menu assignment in the template manager.
You can do this with single articles, categories, sections, or even components. As long as you have a menu link to associate the template to. I always create an Admin only menu to put links that are needed to run the site, but do not need to be accessed by users.
As Brent said, avoid the temptation to modify core Joomla code! Doing this will likely stop you from doing Joomla upgrades 'cos you know it's going to break the core changes that you made.
Apart from the "hidden menu item" technique (which is useful but can break SEF URLs in some situations), a useful tool is Chameleon. This allows you to select specific articles/categories/sections (plus things like browser type, user group, component, whatever) and use these to trigger a certain template.
Though this is an old post, I thought I'd share my thoughts: You can easily change template on a single article, by implementing the onAfterInitialize() - function in a system plugin. No need to modify the Joomla core.
This works for Joomla 1.5, but should also work in 2.5:
function onAfterInitialise(){
if(true){ // f.ex. test for article ID or whatever
JRequest::setVar('template', 'beez'); // change template
}
}
In joomla 3.x versions, url-parameters are handled differently. The following was tested in joomla 3.4.8:
public function onAfterInitialise()
{
$app=JFactory::getApplication();
if(true){ // f.ex. test for article ID or whatever
$app->input->set('template', 'beez3');
}
}
More on writing plugins for Joomla here

TYPO3: Change plugin from USER to USER_INT type

I have a working TYPO3 extension. It is attached this wiki page. How can I change the code of this extension so it is of the USER_INT type? I.e. I don't want TYPO3 to cache the output of this plugin, and want TYPO3 to invoke the extension ever time a page that uses the extension, i.e. disable the caching for this extension.
To disable caching for your extension go to your piX/class.tx_XXX_piX.php file and remove the following line (below your class declaration):
var $pi_checkCHash = true;
You also need to add the following line in the main method (below $this->pi_loadLL();):
$this->pi_USER_INT_obj=1; // Configuring so caching is not expected. This value means that no cHash params are ever set. We do this, because it's a USER_INT object!
grunwalski it's the opposite you have to change this:
t3lib_extMgm::addPItoST43($_EXTKEY,'piX/class.tx_yourextension_piX.php','_piX','list_type',1);
to this:
t3lib_extMgm::addPItoST43($_EXTKEY,'piX/class.tx_yourextension_piX.php','_piX','list_type',0);
The simpliest way to solve your problem is to go back to Extension Maganer, select your extension, choose "Edit in Kickstarter" from the dropdown menu, and then select the corresponding Frontend plugin to edit it's properties.
Check the first checkbox which means that you want your plugins to be rendered as USER_INT cObjects. After that click the View result button, uncheck all custom PHP files (your own code, like modules and plugins) on the right side and click the WRITE button. Please be careful. If you don't uncheck the checkboxes of your own files, they will be overwritten with dummy files.
The correct and comlete way to do this is a combination of the answers of #arturh and #Mehdi Guermazi:
change the last parameter in the addPItoST43() call in ext_localconf.php from 1 to 0
remove the var $pi_checkCHash = true; line from the property definitions in the head of the pi1 class.
add the $this->pi_USER_INT_obj=1; line to the start of the main() function in pi1.
These changes are identical to what you will get when you use the kickstarter method explained in the solution of #bencuss.
When you have created your extension with Kickstarter you also have to go to the file [yourextension]/ext_localconf.php and change this line
t3lib_extMgm::addPItoST43($_EXTKEY,'piX/class.tx_yourextension_piX.php','_piX','list_type',0);
to this:
t3lib_extMgm::addPItoST43($_EXTKEY,'piX/class.tx_yourextension_piX.php','_piX','list_type',1);
Edit the file setup.txt of your extension "myext". Change "USER" into "USER_INT".
plugin.tx_myext = USER_INT
plugin.tx_myxt {
This extension will never be cached.

Resources