public static function videojs_utility::findFieldsByType in Video.js (HTML5 Video Player) 7.3
Finds image fields in the given entity and bundle.
Parameters
$field: Field definition of the video field, used to match image fields when this field is rendered using Views.
$entity_type: Entity type in which the image field must occur.
$bundle: Bundle in which the image field must occur.
Return value
Array of image field names.
1 call to videojs_utility::findFieldsByType()
File
- includes/
videojs.utility.inc, line 188 - This file will be used to keep all utility functions.
Class
- videojs_utility
- Helper functions for the Video.js module.
Code
public static function findFieldsByType($field, $entity_type, $bundle, array $types) {
$resultfields = array();
// Determine the image fields that will be selectable.
if ($entity_type == 'ctools' && $bundle == 'ctools') {
// This is a fake instance (see ctools_fields_fake_field_instance()).
// This occurs for instance when this formatter is used in Views.
// Display all image fields in bundles that contain this field.
$otherfields = field_info_fields();
foreach ($otherfields as $otherfield) {
if (!empty($otherfield['bundles']) && in_array($otherfield['type'], $types)) {
// Find a label by finding an instance label
$instancelabels = array();
$bundles_names = array();
foreach ($otherfield['bundles'] as $otherentitytype => $otherbundles) {
foreach ($otherbundles as $otherbundle) {
// Check if this image field appears in one of the video field bundles.
if (isset($field['bundles'][$otherentitytype]) && in_array($otherbundle, $field['bundles'][$otherentitytype])) {
$otherinstance = field_info_instance($otherentitytype, $otherfield['field_name'], $otherbundle);
$instancelabels[$otherinstance['label']] = isset($instancelabels[$otherinstance['label']]) ? $instancelabels[$otherinstance['label']] + 1 : 1;
$bundles_names[] = t('@entity:@bundle', array(
'@entity' => $otherentitytype,
'@bundle' => $otherbundle,
));
}
}
}
if (!empty($instancelabels)) {
arsort($instancelabels);
$instancelabel = key($instancelabels);
$resultfields[$otherfield['field_name']] = $instancelabel . ' — ' . t('Appears in: @bundles.', array(
'@bundles' => implode(', ', $bundles_names),
));
}
}
}
}
else {
$otherinstances = field_info_instances($entity_type, $bundle);
foreach ($otherinstances as $otherinstance) {
$otherfield = field_info_field_by_id($otherinstance['field_id']);
if (in_array($otherfield['type'], $types)) {
$resultfields[$otherinstance['field_name']] = $otherinstance['label'];
}
}
}
return $resultfields;
}