<?php
/**
* @file
* Featured Photographs Custom Pane.
*/
$plugin = array(
'single' => TRUE,
'title' => t('Featured Photographs from Exhibit'),
'description' => t('Displays Featured Photographs from Exhibit as a carousel.'),
'category' => t('ASP Carousels'),
'render callback' => 'aspcarousels_featured_photographs_exhibit_render',
'defaults' => array(),
'all contexts' => TRUE,
);
/**
* Render the featured photographs pane.
*
* @param $subtype
* @param $conf
* @param $args
* @param null $context
*
* @return \stdClass
* The block as an object.
*/
function aspcarousels_featured_photographs_exhibit_render($subtype, $conf, $args, $context = NULL) {
// Load custom JS only on non-admin pages.
if (arg(0) != 'admin') {
drupal_add_js(file_create_url(drupal_get_path('module', 'aspcarousels') . '/js/FeaturedPhotographs.js', array('preprocess' => FALSE)));
}
// Load Exhibit from URL.
// Make sure we are on exhibit entity and the id is in the URL.
if (isset($args[0]) && isset($args[2]) && ('exhibit' == $args[0]) && (is_numeric($args[2]))) {
$entity = entity_load_single('exhibit', $args[2]);
}
// Exhibit ID.
$exhibitID = $entity->id;
// Featured People.
// Get list of Featured People IDs.
$exhibitFeaturedPeopleReferenceID = $entity->field_featured_photographers['und'];
// Loop through each People entity.
foreach ($exhibitFeaturedPeopleReferenceID as $key => $val) {
// Get Exhibit ID from array.
$exhibitFeaturedPeopleID = $exhibitFeaturedPeopleReferenceID[$key]['target_id'];
}
// File.
// File Entity Query.
$queryFileEntity = new EntityFieldQuery();
$queryFileEntity->entityCondition('entity_type', 'file')
->entityCondition('bundle', 'image')
->fieldCondition('field_featured_for_exhibit', 'value', '1')
->fieldCondition('field_exhibit_reference', 'target_id', $exhibitID);
$entityFile = $queryFileEntity->execute();
// Get list of File IDs.
$file = $entityFile['file'];
// Loop through each File entity.
foreach ($file as $key => $val) {
// Get the File ID.
$fileID = $file[$key]->fid;
// Load each file.
$fileEntity = entity_load_single('file', $fileID);
// People ID.
$peopleID = $fileEntity->field_photographer_reference['und'];
// Default People Name to empty.
$peopleName = '';
// Loop through each People entity.
foreach ($peopleID as $key => $val) {
// Get People ID from array.
$peopleIDValue = $peopleID[$key]['target_id'];
// Load each People entity.
$peopleEntity = entity_load_single('people', $peopleIDValue);
// People name.
$nameArray = $peopleEntity->field_name['und'][0];
// First, Middle, Last name.
(!empty($nameArray['given']))
? $firstName = $nameArray['given'] . ' '
: $firstName = NULL;
(!empty($nameArray['middle']))
? $middleName = $nameArray['middle'] . ' '
: $middleName = NULL;
(!empty($nameArray['family']))
? $lastName = $nameArray['family']
: $lastName = NULL;
// People name combined.
$peopleName = $firstName . $middleName . $lastName;
}
// File image.
$fileImage = file_create_url($fileEntity->uri);
// Caption.
$imageCaption = $fileEntity->field_caption[und][0]['value'];
// Credit.
if (!empty($fileEntity->field_credit[und][0]['value'])) {
$imageCredit = $fileEntity->field_credit[und][0]['value'];
} elseif (!empty($peopleName)) {
$imageCredit = $peopleName;
} else {
$imageCredit = '';
}
// Display name.
$displayName = $fileEntity->field_display_name[und][0]['value'];
$displayNameMarkup = '<div class="field-display-name">' . $displayName . '</div>';
// Share URL.
$url = $GLOBALS['base_url'] . '/' . drupal_get_path_alias();
$urlShare = $url . '?fpGallery=' . $fileID;
// Image.
$img_uri = file_load($fileID)->uri;
$img_path = file_create_url($img_uri);
$img = l(theme('image', array('path' => $img_path)),
$img_path,
array(
'html' => TRUE,
'attributes' =>
array(
'id' => 'fpId-' . $fileID,
'class' => 'fpGallery',
'rel' => 'fpGallery',
'data-title' => $displayName,
'data-photographer' => $imageCredit,
'data-caption' => $imageCaption,
'data-share' => '<h2 class="title">' . t('Share') . '</h2><div class="ShareThis"><div class="sharethis-wrapper"><span st_url="' . $urlShare . '" st_title="' . $peopleName . '" class="st_facebook_custom" displaytext="facebook"></span><span st_url="' . $urlShare . '" st_title="' . $peopleName . '" class="st_twitter_custom" displaytext="twitter"></span><span st_url="' . $urlShare . '" st_title="' . $peopleName . '" class="st_googleplus_custom" displaytext="googleplus"></span><span st_url="' . $urlShare . '" st_title="' . $peopleName . '" class="st_email_custom" displaytext="email"></span></div></div>'
)
)
);
// Output.
$output[] = theme('aspcarousel_slide_fp', array(
'img' => $img,
'photographername' => $displayNameMarkup . $imageCredit,
));
$exhibitFeaturedPeopleFP_output = implode('', $output);
}
// Add classes.
$classes_array = array('aspect-564x571');
$classes = ' ' . implode(' ', $classes_array);
// Render as a block.
$block = new stdClass();
$block->content = isset($exhibitFeaturedPeopleFP_output)
? theme('aspcarousel_fp', array(
'slides' => $exhibitFeaturedPeopleFP_output,
'title' => 'Featured Photographs',
'classes' => $classes,
'slide_count' => count($slides),
))
: '';
return $block;
}