summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoloc2012-11-27 19:50:57 (GMT)
committer Moloc2012-11-27 19:50:57 (GMT)
commit761f764475d5d947de919dca2e2f3df9b71ef348 (patch)
tree8c244139b17f51b57b58b08e3c127de779ec691c
parent36ce8c697da31d6b91e9852f178ac4c07f5cb1b4 (diff)
Issue #1848908 by Moloc: Revert file field support for media_gallery 1.x7.x-1.x
-rw-r--r--media_gallery.fields.inc22
-rw-r--r--media_gallery.module46
-rw-r--r--media_gallery.pages.inc33
3 files changed, 20 insertions, 81 deletions
diff --git a/media_gallery.fields.inc b/media_gallery.fields.inc
index 029087c..307cdbb 100644
--- a/media_gallery.fields.inc
+++ b/media_gallery.fields.inc
@@ -13,7 +13,7 @@ function media_gallery_field_formatter_info() {
return array(
'media_gallery' => array(
'label' => t('Gallery media'),
- 'field types' => array('media', 'file'),
+ 'field types' => array('media'),
'settings' => array('file_view_mode' => 'media_gallery_thumbnail'),
),
);
@@ -89,20 +89,14 @@ function media_gallery_field_formatter_view($entity_type, $entity, $field, $inst
// Prepare the referenced file entities for viewing.
$files = array();
foreach ($items as $delta => $item) {
- if (empty($item['file'])) {
- // file field
- $file = file_load($item['fid']);
- // Don't try to display files which no longer exist.
- if ($file === FALSE) {
- unset($items[$delta]);
- continue;
- }
- }
- else {
- // media field
- $file = $item['file'];
+ // Don't try to display files which no longer exist.
+ if (!isset($item['file'])) {
+ unset($items[$delta]);
+ continue;
}
+ $file = $item['file'];
+
// Pass along formatter reference field values from the gallery to the file.
foreach ($formatter_reference_fields as $field_name) {
if (!isset($file->{$field_name}) && isset($entity->{$field_name})) {
@@ -125,7 +119,7 @@ function media_gallery_field_formatter_view($entity_type, $entity, $field, $inst
// View each file. We don't use file_view_multiple(), because we need the
// render array indexed by $delta rather than by file id.
foreach ($items as $delta => $item) {
- $element[$delta] = file_view($files[$item['fid']], $file_view_mode, $langcode);
+ $element[$delta] = file_view($item['file'], $file_view_mode, $langcode);
$element[$delta]['#media_gallery_entity_type'] = $entity_type;
$element[$delta]['#media_gallery_entity'] = $entity;
switch ($file_view_mode) {
diff --git a/media_gallery.module b/media_gallery.module
index c017b9e..af72cd3 100644
--- a/media_gallery.module
+++ b/media_gallery.module
@@ -895,11 +895,9 @@ function media_gallery_form($node, $form_state) {
* Implements hook_form_alter().
*/
function media_gallery_form_alter(&$form, &$form_state, $form_id) {
- if (strpos($form_id, 'media_edit') === 0 || strpos($form_id, 'file_entity_edit') === 0) {
+ if (strpos($form_id, 'media_edit') === 0) {
// Act on both the regular and multiform versions of the edit form.
- // regular: $form_id depends on media version
- // multiform: $form_id is always 'media_edit'
- if (in_array($form_id, array('media_edit', 'file_entity_edit')) || preg_match('/^(media|file_entity)_edit_[0-9]+$/', $form_id)) {
+ if ($form_id === 'media_edit' || preg_match('/^media_edit_[0-9]+$/', $form_id)) {
// Prepopulate the media_edit form with our best guess at the image title.
if (!empty($form['media_title']) && empty($form['media_title'][LANGUAGE_NONE][0]['value']['#default_value'])) {
$fid = $form['fid']['#value'];
@@ -1024,17 +1022,6 @@ function media_gallery_form_media_gallery_node_form_alter(&$form, &$form_state)
* Implements hook_form_FORM_ID_alter().
*/
function media_gallery_form_media_edit_alter(&$form, &$form_state) {
- _media_gallery_form_media_edit_alter($form, $form_state, 'media_edit');
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- */
-function media_gallery_form_file_entity_edit_alter(&$form, &$form_state) {
- _media_gallery_form_media_edit_alter($form, $form_state, 'file_entity_edit');
-}
-
-function _media_gallery_form_media_edit_alter(&$form, &$form_state, $form_id) {
// Adjust the media edit form when it is shown within a gallery context.
if (isset($form_state['media_gallery']['gallery'])) {
// Remove the Delete button, since media entities can't be deleted when they
@@ -1051,9 +1038,9 @@ function _media_gallery_form_media_edit_alter(&$form, &$form_state, $form_id) {
// Make sure to add this for the form-level submit handlers and also for the
// button-level submit handlers of the "Save" button, in case those are
// being used.
- $form['#submit'][] = 'media_gallery_' . $form_id . '_submit';
+ $form['#submit'][] = 'media_gallery_media_edit_submit';
if (isset($form['actions']['submit']['#submit'])) {
- $form['actions']['submit']['#submit'][] = 'media_gallery_' . $form_id . '_submit';
+ $form['actions']['submit']['#submit'][] = 'media_gallery_media_edit_submit';
}
}
// On the media gallery multiedit page, add a "Remove" checkbox to each item.
@@ -1119,15 +1106,6 @@ function media_gallery_media_edit_submit($form, &$form_state) {
}
/**
- * Form submit handler for file_entity edit form in gallery context.
- *
- * @see media_gallery_form_media_edit_alter()
- */
-function media_gallery_file_entity_edit_submit($form, &$form_state) {
- media_gallery_media_edit_submit($form, $form_state);
-}
-
-/**
* Implements hook_field_attach_form().
*/
function media_gallery_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode) {
@@ -1850,19 +1828,3 @@ function media_gallery_lightbox_delivery_callback($page_content) {
}
media_gallery_lightbox_page_deliver($page_content);
}
-
-/**
- * Returns the version of the media module.
- */
-function _media_gallery_media_version() {
- $media_info = system_get_info('module', 'media');
- if (isset($media_info['version'])) {
- if (strpos($media_info['version'], '7.x-1') === 0) {
- return '1.x';
- }
- else {
- return '2.x';
- }
- }
- return FALSE;
-}
diff --git a/media_gallery.pages.inc b/media_gallery.pages.inc
index 3ac50b8..161b8da 100644
--- a/media_gallery.pages.inc
+++ b/media_gallery.pages.inc
@@ -300,12 +300,8 @@ function media_gallery_add_images($node) {
if (empty($existing_fids[$fid])) {
$file = Array();
$file['fid'] = $fid;
- // media field settings
$file['title'] = NULL;
$file['data'] = '';
- // file field settings
- $file['display'] = 1;
- $file['description'] = '';
$items[] = $file;
}
}
@@ -374,20 +370,12 @@ function media_gallery_media_page_edit($gallery, $file) {
l($gallery->title, $node_url_arguments['path'], $node_url_arguments['options']),
));
- if (_media_gallery_media_version() == '1.x') {
- // We'll be reusing Media module's 'media_edit' form, so we need to load its
- // include file. In addition to loading it here, we also set the include file
- // info within $form_state in case there are AJAX enabled widgets that will
- // submit to system/ajax, bypassing this menu callback.
- module_load_include('inc', 'media', 'includes/media.pages');
- $form_state['build_info']['files']['menu'] = array('type' => 'inc', 'module' => 'media', 'name' => 'media.pages');
- $form_id = 'media_edit';
- }
- else {
- module_load_include('inc', 'file_entity', 'file_entity.pages');
- $form_state['build_info']['files']['menu'] = array('type' => 'inc', 'module' => 'file_entity', 'name' => 'file_entity.pages');
- $form_id = 'file_entity_edit';
- }
+ // We'll be reusing Media module's 'media_edit' form, so we need to load its
+ // include file. In addition to loading it here, we also set the include file
+ // info within $form_state in case there are AJAX enabled widgets that will
+ // submit to system/ajax, bypassing this menu callback.
+ module_load_include('inc', 'media', 'includes/media.pages');
+ $form_state['build_info']['files']['menu'] = array('type' => 'inc', 'module' => 'media', 'name' => 'media.pages');
// Provide context information for form building and processing functions.
$form_state['media_gallery']['gallery'] = $gallery;
@@ -395,7 +383,7 @@ function media_gallery_media_page_edit($gallery, $file) {
// Since we have a $form_state, we can't call drupal_get_form(), so pass the
// expected arguments to drupal_build_form().
$form_state['build_info']['args'] = array($file);
- return drupal_build_form($form_id, $form_state);
+ return drupal_build_form('media_edit', $form_state);
}
/**
@@ -421,12 +409,7 @@ function media_gallery_media_page_multiedit($node) {
module_load_include('inc', 'media', 'includes/media.pages');
// Build and process the form.
- if (_media_gallery_media_version() == '1.x') {
- $form = media_page_multiedit($files);
- }
- else {
- $form = media_file_page_edit_multiple($files);
- }
+ $form = media_page_multiedit($files);
// Override the page title set by media_page_multiedit() and return the form.
drupal_set_title(t('<em>Edit media for</em> @title', array('@type' => $node->type, '@title' => $node->title)), PASS_THROUGH);