You are here

function royalslider_preprocess_royalslider in RoyalSlider Integration 7

Implements hook_preprocess_HOOK().

Preprocess variables for the RoyalSlider template.

File

theme/royalslider.theme.inc, line 12
Theme functions for RoyalSlider.

Code

function royalslider_preprocess_royalslider(&$variables) {

  // Load optionset.
  if ($optionset = royalslider_optionset_load($variables['optionset'])) {
    $variables['settings'] = $optionset->options;

    // Add wrapper attributes.
    $variables['attributes_array']['class'][] = 'royalSlider';
    $variables['attributes_array']['id'] = $variables['royalslider_id'];

    // Setup skin & fallback to default.
    $skin = !empty($variables['skin']) ? $variables['skin'] : $optionset->skin;
    $skins = royalslider_skins();
    $skin_class = isset($skins[$skin]['class']) ? $skins[$skin]['class'] : $skins['default']['class'];
    $variables['attributes_array']['class'][] = $skin_class;

    // @TODO figure out if we can calculate the largest image size and use it
    // as a base for automatically setting the slider size.
    // Now prepare items for rendering.
    $items_processed = array();
    foreach ($variables['items'] as $item) {
      $items_processed[] = array(
        '#theme' => 'royalslider_item',
        '#royalslider_id' => $variables['royalslider_id'],
        '#optionset' => $optionset,
        '#item' => $item,
      );
    }
    $variables['items_processed'] = $items_processed;

    // The attributes_array is overridden by ctools see issue #2645612.
    // This workaround copies them to the classes_array to mitigate the issue
    // that the skin is missing and the royalSlider class has a lowercase s.
    // See #2793037 for more details.
    $variables['classes_array'] = $variables['attributes_array']['class'];
    if (!empty($items_processed)) {

      // Add resources.
      royalslider_add($variables['royalslider_id'], $optionset, $skin);

      // We're done!
      return;
    }
  }
}