Skip to content

Instantly share code, notes, and snippets.

@steffenr
Last active December 13, 2015 16:58
Show Gist options
  • Save steffenr/4943967 to your computer and use it in GitHub Desktop.
Save steffenr/4943967 to your computer and use it in GitHub Desktop.
Domain Access - imagestyles per Domain
<?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;
}
<?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