function bootstrap_field_load_carousel in Bootstrap Core 7.3
Helper function for retrieving Bootstrap Carousel slide items.
Parameters
array|int $fids: An indexed array of {file_managed}.fid or an single fid integer.
array $conditions: An associative array of conditions which to filter by. Can be one of:
- entity_id: An entity identifier.
- entity_type: An entity type.
- entity_bundle: An entity bundle type.
Return value
array An associative array where the key is the fid associated with this slide and the value is the DB entry object containing:
- fid: The {file_managed}.fid association.
- entity_id: An entity identifier.
- entity_type: An entity type.
- entity_bundle: An entity bundle type.
- title: The slide title.
- description: The slide description.
- url: The slide URL.
3 calls to bootstrap_field_load_carousel()
- bootstrap_field_field_formatter_view in bootstrap_field/
includes/ carousel.inc - Implements hook_field_formatter_view().
- bootstrap_field_image_widget_carousel_process in bootstrap_field/
includes/ carousel.inc - A callback for #process.
- bootstrap_field_image_widget_carousel_value in bootstrap_field/
includes/ carousel.inc - A callback for #file_value_callbacks.
File
- bootstrap_field/
includes/ carousel.inc, line 54 - carousel.inc
Code
function bootstrap_field_load_carousel($fids = array(), $conditions = array()) {
if (!is_array($fids)) {
$fids = array(
(int) $fids,
);
}
// Default values.
$defaults = bootstrap_field_carousel_defaults();
if (isset($conditions['entity_id'])) {
$defaults->entity_id = (int) $conditions['entity_id'];
}
elseif (isset($conditions['entity']) && isset($conditions['entity_type'])) {
$info = entity_get_info($conditions['entity_type']);
$key = isset($info['entity keys']['name']) ? $info['entity keys']['name'] : $info['entity keys']['id'];
$defaults->entity_id = isset($conditions['entity']->{$key}) ? (int) $conditions['entity']->{$key} : 0;
}
if (isset($conditions['entity_type'])) {
$defaults->entity_type = $conditions['entity_type'];
}
if (isset($conditions['entity_bundle'])) {
$defaults->entity_bundle = $conditions['entity_bundle'];
}
// Retrieve database entry. If a field instance is provided, check to see
// if it has the bootstrap_carousel fields enabled (i.e. prevent unnecessary
// database calls).
$results = array();
if (!isset($conditions['instance']['widget']['settings']) || $conditions['instance']['widget']['settings']['bootstrap_carousel']) {
$query = db_select('bootstrap_carousel', 'bc')
->fields('bc');
if ($fids) {
$query
->condition('fid', $fids);
}
if (isset($conditions['entity_id'])) {
// We must use an OR condition here. New entities that are saved do not
// yet have an entity ID, so a temporary -1 value is used instead.
$query
->condition(db_or()
->condition('entity_id', $conditions['entity_id'])
->condition('entity_id', -1));
}
if (isset($conditions['entity_type'])) {
$query
->condition('entity_type', $conditions['entity_type']);
}
if (isset($conditions['entity_bundle'])) {
$query
->condition('entity_bundle', $conditions['entity_bundle']);
}
$results = $query
->execute()
->fetchAllAssoc('fid');
}
// Iterate over each result.
$integers = array(
'cid',
'fid',
'entity_id',
);
foreach ($results as $fid => $result) {
$results[$fid] = clone $defaults;
foreach ((array) $result as $name => $value) {
if (empty($value)) {
continue;
}
elseif (in_array($name, $integers)) {
$value = (int) $value;
}
elseif ($name === 'settings') {
$value = unserialize($value);
}
$results[$fid]->{$name} = $value;
}
}
// Always provide default valued results for each of the $fids.
if (!$results) {
foreach ($fids as $fid) {
$results[$fid] = $defaults;
$results[$fid]->fid = $fid;
}
}
return $results;
}