Last active
December 13, 2015 16:58
-
-
Save steffenr/4943967 to your computer and use it in GitHub Desktop.
Domain Access - imagestyles per Domain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Helper function to get current machine_name of domain. | |
* - used in preprocess functions for setting corresponding image-styles for fields | |
* @return string | |
* machine_name of current domain | |
*/ | |
function my_module_get_domain_machine_name() { | |
$machine_name = ''; | |
// Get machine_name for actual domain. | |
$domain = domain_get_domain(); | |
if (!empty($domain) && !$domain['is_default']) { | |
$machine_name = $domain['machine_name']; | |
} | |
return $machine_name; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_preprocess_node(). | |
*/ | |
function my_module_preprocess_node(&$vars) { | |
// Check for node-type we want to preprocess. | |
if ($vars['type'] == '{my_content_type}') { | |
// Get machine name for domain. | |
$domain_name = my_module_get_domain_machine_name(); | |
// Lookup field with image-style and add domain-name to style name. | |
if (!empty($vars['content']['field_image'])) { | |
$current_style = $vars['content']['field_image'][0]['#image_style']; | |
$variables['content']['field_image'][0]['#image_style'] = implode('_', array($current_style, $domain_name)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment