Hi everyone,

I'm trying to build a style plugin which takes an image attached to an entity and sets it as the background of a container div. I've been using this tutorial as a guide, but I can't seem to get it to work. The key seems to be this line of the render callback:

$image_abs_path = ctools_context_keyword_substitute($vars['settings']['image'], array(), $vars['display']->context);

, but $vars['display']->context appears to be empty.
screenshot

Here is my plugin's .inc file:

<?php

$plugin = array(
  'title' => t('Background picture'),
  'description' => t('Background picture style.'),
  'render pane' => 'background_picture_style_render_pane',
  'hook theme' => array(
    'background_picture_style' => array(
      'variables' => array(
        'content' => NULL,
        'style_attributes' => NULL,
      ),
      'path' => drupal_get_path('theme', 'icmp_launch') . '/panels/styles/background_picture',
      'template' => 'background-picture',
    ),
  ),
  'pane settings form' => 'background_picture_style_settings_form',
);

/**
 * Settings form callback.
 */
function background_picture_style_settings_form($form, $form_state) {
  $form['image'] = array(
    '#type' => 'textfield',
    '#title' => t('Image field'),
    '#description' => t('Enter the image field for the background image. You may use substitutions in this field. E.g. for the default image field attached to articles use "%node:field_image"'),
    '#required' => TRUE,
    '#default_value' => (isset($form['image'])) ? $form['image'] : '',
  );
  $form['image_style'] = array(
    '#type' => 'select',
    '#title' => t('Image Style'),
    '#description' => t('Choose the appropriate image style for the background image.'),
    '#options' => image_style_options(),
    '#default_value' => (isset($form['image_style'])) ? $form['image_style'] : '',
  );
  $form['class'] = array(
    '#type' => 'textfield',
    '#title' => t('CSS Classes'),
    '#description' => t('Enter CSS classes for this style. Separate multiple classes by spaces.'),
    '#default_value' => (isset($form['class'])) ? $form['class'] : '',
  );

  return $form;
}

/**
 * Render callback.
 */
function theme_background_picture_style_render_pane($vars) {

  $content = $vars['content']->content;
  $style_attributes = array();
  $image_url = NULL;

  // Get the absolute path of the original image from the context substitution
  $image_abs_path = ctools_context_keyword_substitute($vars['settings']['image'], array(), $vars['display']->context);

  $image_style = $vars['settings']['image_style'];

  if ($image_style == '') {
    // If no image style is selected, use the original image.
    $image_url = $image_abs_path;
  } else {
    // Image style is provided in the settings form.
    // We need to get the original image uri to return the URL for an image derivative.
    global $base_url;
    $files_rel_path = variable_get('file_public_path', conf_path() . '/files');
    $image_rel_path = str_replace($base_url . '/' . $files_rel_path, '', $image_abs_path);
    $image_uri = file_build_uri($image_rel_path);

    $image_style_url = image_style_url($image_style, $image_uri);

    $image_url = $image_style_url;
  }

  $style_attributes['style'] = 'background-image: url(' . $image_url . ');';

  // Add our classes to the attrubutes array, if any defined
  if ($vars['settings']['class']) {
    $style_attributes['class'] = explode(' ', $vars['settings']['class']);
  }

  return theme('background_picture_style', array(
    'content' => $content,
    'style_attributes' => $style_attributes,
    )
  );
}

According to the tutorial page, this should work (note: I've changed the above code from a region style plugin to a pane style plugin, though I have the same missing context array problem both ways). I'm unsure of how to proceed, should I be passing a context to the panel? Also, the content pane is generated by Views, but I've tried using a regular node with the same result.

Any help would be greatly appreciated.

Thanks!

CommentFileSizeAuthor
Screen Shot 2014-11-08 at 4.40.18 AM.png32.42 KBridgek
Support from Acquia helps fund testing for Drupal Acquia logo