summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorrit Schippers2013-02-11 07:17:38 (GMT)
committer Jorrit Schippers2013-02-11 07:17:38 (GMT)
commite489e52c1be198c7057168ca6d5e1e0c724ccee8 (patch)
treeb8bba901c8ed30c47c5f42bd3cb149ba95cdd893
parentb2f6f50a15769c9823e0da5c726d2af705a3ca15 (diff)
Issue #1906206 by Jorrit: Fixed notices when trying to setup the player as File Entity display.7.x-2.3
-rw-r--r--videojs.module120
1 files changed, 70 insertions, 50 deletions
diff --git a/videojs.module b/videojs.module
index 36d2601..dff1356 100644
--- a/videojs.module
+++ b/videojs.module
@@ -149,47 +149,8 @@ function videojs_field_formatter_settings_form($field, $instance, $view_mode, $f
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$image_styles = image_style_options(FALSE);
-
- // Determine the image fields that will be selectable.
- if ($instance['entity_type'] == 'ctools' && $instance['bundle'] == 'ctools') {
- // This is a fake instance (see ctools_fields_fake_field_instance())
- // Display all image fields in bundles that contain this field.
- $otherfields = field_info_fields();
- foreach ($otherfields as $otherfield) {
- if ($otherfield['type'] == 'image' && !empty($otherfield['bundles'])) {
- // 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);
- $imagefields[$otherfield['field_name']] = $instancelabel . ' — ' . t('Appears in: @bundles.', array('@bundles' => implode(', ', $bundles_names)));
- }
- }
- }
- }
- else {
- $otherinstances = field_info_instances($instance['entity_type'], $instance['bundle']);
- $imagefields = array();
-
- foreach ($otherinstances as $otherinstance) {
- $otherfield = field_info_field_by_id($otherinstance['field_id']);
- if ($otherfield['type'] == 'image') {
- $imagefields[$otherinstance['field_name']] = $otherinstance['label'];
- }
- }
+ if (isset($instance['entity_type']) && isset($instance['bundle'])) {
+ $imagefields = _videojs_find_image_fields($field, $instance['entity_type'], $instance['bundle']);
}
$form = array(
@@ -223,20 +184,79 @@ function videojs_field_formatter_settings_form($field, $instance, $view_mode, $f
'#empty_value' => NULL,
'#empty_option' => t('- None -'),
);
+ $form['posterimage_style'] = array(
+ '#title' => t('Poster image style'),
+ '#type' => 'select',
+ '#default_value' => $settings['posterimage_style'],
+ '#empty_option' => t('None (original image)'),
+ '#description' => t('The original video thumbnail will be displayed. Otherwise, you can add a custom image style at !settings.', array('!settings' => l(t('media image styles'), 'admin/config/media/image-styles'))),
+ '#options' => $image_styles,
+ );
}
- $form['posterimage_style'] = array(
- '#title' => t('Poster image style'),
- '#type' => 'select',
- '#default_value' => $settings['posterimage_style'],
- '#empty_option' => t('None (original image)'),
- '#description' => t('The original video thumbnail will be displayed. Otherwise, you can add a custom image style at !settings.', array('!settings' => l(t('media image styles'), 'admin/config/media/image-styles'))),
- '#options' => $image_styles,
- );
-
return $form;
}
+/**
+ * Finds image fields in the given entity and bundle.
+ *
+ * @param $field
+ * Field definition of the video field, used to match image fields when
+ * this field is rendered using Views.
+ * @param $entity_type
+ * Entity type in which the image field must occur.
+ * @param $bundle
+ * Bundle in which the image field must occur.
+ * @return
+ * Array of image field names.
+ */
+function _videojs_find_image_fields($field, $entity_type, $bundle) {
+ $imagefields = 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 ($otherfield['type'] == 'image' && !empty($otherfield['bundles'])) {
+ // 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);
+ $imagefields[$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 ($otherfield['type'] == 'image') {
+ $imagefields[$otherinstance['field_name']] = $otherinstance['label'];
+ }
+ }
+ }
+
+ return $imagefields;
+}
+
function videojs_field_formatter_settings_form_validate($form, $form_state) {
$width = $form['width']['#value'];
$height = $form['height']['#value'];