function backstretch_context_reaction_backstretch::execute in Backstretch 7.2
Same name and namespace in other branches
- 7 plugins/backstretch_context_reaction_backstretch.inc \backstretch_context_reaction_backstretch::execute()
File
- plugins/backstretch_context_reaction_backstretch.inc, line 284
- Backstretch reaction class for Context integration.
Class
- backstretch_context_reaction_backstretch
- @file
Backstretch reaction class for Context integration.
Code
function execute() {
foreach ($this
->get_contexts() as $context) {
if (!empty($context->reactions[$this->plugin])) {
static $id = 1;
$settings = $context->reactions[$this->plugin];
$source = $settings['source']['type'];
$formatters = backstretch_field_formatter_info();
$default = $formatters['backstretch']['settings'];
$options_info = backstretch_formatter_options();
$options = array();
foreach ($settings as $name => $value) {
if (array_key_exists($name, $options_info)) {
$option = $options_info[$name];
$js = isset($option['js']) ? $option['js'] : '';
if ($name == 'element' || $name == 'element_other' && $settings['element'] == '') {
continue;
}
if ($value != $default[$name] && $js) {
$options[$js] = $value;
}
if ($name == 'fade' && $value != $default[$name] && is_numeric($value) && intval($value) == $value) {
$options[$name] = (int) $options[$name];
}
}
}
switch ($source) {
case 'entity':
$entity_type = $settings['source']['entity']['entity_type'];
$field = isset($settings['source']['entity']['field']) ? $settings['source']['entity']['field'] : '';
$entity_ids = $settings['source']['entity']['ids'];
$entity_ids = explode(',', $entity_ids);
if (!$entity_type || !$entity_ids) {
return;
}
$entities = entity_load($entity_type, $entity_ids);
foreach ($entities as $entity) {
if (isset($entity->fid) && isset($entity->uri)) {
$options['items'][] = file_create_url($entity->uri);
continue;
}
$items = field_get_items($entity_type, $entity, $field);
foreach ($items as &$item) {
$uri = $item['uri'];
if ($settings['image_style']) {
$url = image_style_url($settings['image_style'], $uri);
}
else {
$url = file_create_url($uri);
}
$options['items'][] = $url;
}
}
break;
case 'path':
$paths = $settings['source']['path'];
$paths = explode("\n", $paths);
foreach ($paths as $key => $path) {
$path = trim($path);
$paths[$key] = url($path);
if ($settings['image_style']) {
$uri = file_build_uri(drupal_basename($path));
$paths[$key] = image_style_url($settings['image_style'], $uri);
}
}
$options['items'] = $paths;
break;
}
if ($settings['random']) {
$random_key = array_rand($options['items']);
$options['items'] = array(
$options['items'][$random_key],
);
}
$element = array(
'#theme' => 'backstretch',
'#id' => 'backstretch-' . $id,
'#options' => $options,
);
$id++;
return drupal_render($element);
}
}
}