summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoloc2012-12-05 19:52:33 (GMT)
committer Moloc2012-12-05 19:52:33 (GMT)
commit660d8772b728e158c59b33735e030401b6b6e75f (patch)
treea6d0972a90d8a5ca167d795dbae2090dac988612
parent29030901a0c5dfc20d770af80433be9c7a7bfe73 (diff)
Issue #1848914: Changed from media-field to file-field.
-rw-r--r--colorbox-display.js2
-rw-r--r--media_gallery.dragdrop.css2
-rw-r--r--media_gallery.dragdrop.js2
-rw-r--r--media_gallery.fields.inc21
-rw-r--r--media_gallery.install11
-rw-r--r--media_gallery.module62
-rw-r--r--media_gallery.pages.inc16
-rw-r--r--media_gallery.theme.inc12
8 files changed, 62 insertions, 66 deletions
diff --git a/colorbox-display.js b/colorbox-display.js
index 195ce1f..2341ab2 100644
--- a/colorbox-display.js
+++ b/colorbox-display.js
@@ -4,7 +4,7 @@ Drupal.behaviors.mediaGalleryColorbox.attach = function (context, settings) {
var $ = jQuery, $galleries, $gallery, href, $links, $link, $dummyLinksPre, $dummyLinksPost, i, j;
if ($.fn.colorbox) {
// Add a colorbox group for each media gallery field on the page.
- $galleries = $('.field-name-media-gallery-media');
+ $galleries = $('.field-name-media-gallery-file');
for (i = 0; i < $galleries.length; i++) {
$gallery = $($galleries[i]);
$links = $('a.cbEnabled', $gallery);
diff --git a/media_gallery.dragdrop.css b/media_gallery.dragdrop.css
index 1e7207c..66900ee 100644
--- a/media_gallery.dragdrop.css
+++ b/media_gallery.dragdrop.css
@@ -47,6 +47,6 @@
/* Don't gray out images while drag-and-drop is disabled; webkit doesn't seem
to handle the opacity change correctly. */
-.field-name-media-gallery-media .media-gallery-sortable-processed.ui-state-disabled {
+.field-name-media-gallery-file .media-gallery-sortable-processed.ui-state-disabled {
opacity: inherit;
}
diff --git a/media_gallery.dragdrop.js b/media_gallery.dragdrop.js
index b2e789c..8af15cd 100644
--- a/media_gallery.dragdrop.js
+++ b/media_gallery.dragdrop.js
@@ -69,7 +69,7 @@ Drupal.mediaGallerySort.handle_update = function (event, ui) {
/**
* Change ID attributes of sorted items to reflect the new order.
*
- * Individual media items in the media_gallery_media field don't have a primary
+ * Individual media items in the media_gallery_file field don't have a primary
* key, so we're sorting by their delta. When their delta changes on the server
* side, we need to reflect it on the client side as well.
*/
diff --git a/media_gallery.fields.inc b/media_gallery.fields.inc
index 307cdbb..74a030c 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'),
+ 'field types' => array('file'),
'settings' => array('file_view_mode' => 'media_gallery_thumbnail'),
),
);
@@ -89,13 +89,7 @@ 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) {
- // Don't try to display files which no longer exist.
- if (!isset($item['file'])) {
- unset($items[$delta]);
- continue;
- }
-
- $file = $item['file'];
+ $file = (object)$item;
// Pass along formatter reference field values from the gallery to the file.
foreach ($formatter_reference_fields as $field_name) {
@@ -119,7 +113,10 @@ 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($item['file'], $file_view_mode, $langcode);
+ // Use $file in $files instead of $item,
+ // because $item does not contain the object modifications.
+ $file = (object)$item;
+ $element[$delta] = file_view($files[$file->fid], $file_view_mode, $langcode);
$element[$delta]['#media_gallery_entity_type'] = $entity_type;
$element[$delta]['#media_gallery_entity'] = $entity;
switch ($file_view_mode) {
@@ -149,7 +146,7 @@ function media_gallery_field_formatter_view($entity_type, $entity, $field, $inst
*
* During normal gallery node display, the Field Attach API ensures that all of
* its fields get rendered. Sometimes, however, we need to display just a single
- * media entity (one item from the multi-valued "media_gallery_media" field)
+ * media entity (one item from the multi-valued "media_gallery_file" field)
* without displaying any other media entities within that field, and without
* displaying any other gallery node fields, but via a field formatter.
*
@@ -159,11 +156,11 @@ function media_gallery_field_formatter_view($entity_type, $entity, $field, $inst
function media_gallery_item_view($gallery_node, $file, $file_view_mode) {
$display = array('type' => 'media_gallery', 'settings' => array('file_view_mode' => $file_view_mode));
$id = $gallery_node->nid;
- $field_name = 'media_gallery_media';
+ $field_name = 'media_gallery_file';
$field = field_info_field($field_name);
$instance = field_info_instance('node', $field_name, 'media_gallery');
$langcode = key($gallery_node->{$field_name});
- $items = array(0 => array('fid' => $file->fid, 'file' => $file));
+ $items = array(0 => $file);
$items_multi = array($id => &$items); // Taken by reference, so can't inline.
$formatter = field_info_formatter_types($display['type']);
// "prepare_view" function is optional.
diff --git a/media_gallery.install b/media_gallery.install
index 358b62b..4d468fc 100644
--- a/media_gallery.install
+++ b/media_gallery.install
@@ -179,11 +179,10 @@ function media_gallery_schema() {
function _media_gallery_controlled_fields() {
$fields = array(
// The media items that make up the gallery.
- 'media_gallery_media' => array(
- 'field_name' => 'media_gallery_media',
+ 'media_gallery_file' => array(
+ 'field_name' => 'media_gallery_file',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
- 'locked' => TRUE,
- 'type' => 'media',
+ 'type' => 'file',
),
// The gallery description.
'media_gallery_description' => array(
@@ -361,8 +360,8 @@ function _media_gallery_controlled_instances($group = NULL) {
),
),
),
- 'media_gallery_media' => array(
- 'field_name' => 'media_gallery_media',
+ 'media_gallery_file' => array(
+ 'field_name' => 'media_gallery_file',
'label' => $t('Gallery media'),
'widget' => array(
'type' => 'media_generic',
diff --git a/media_gallery.module b/media_gallery.module
index af72cd3..ecb6ee2 100644
--- a/media_gallery.module
+++ b/media_gallery.module
@@ -245,13 +245,13 @@ function media_gallery_menu_local_tasks_alter(&$data, $router_item, $root_path)
* Implements hook_node_load().
*/
function media_gallery_node_load($nodes, $types) {
- // Store a copy of the media_gallery_media field before mucking with it in
+ // Store a copy of the media_gallery_file field before mucking with it in
// media_gallery_view(). We use hook_node_load() instead of hook_load(),
// because the latter runs before fields are loaded.
if (in_array('media_gallery', $types)) {
foreach ($nodes as $node) {
if ($node->type == 'media_gallery') {
- $node->media_gallery_media_original = $node->media_gallery_media;
+ $node->media_gallery_file_original = $node->media_gallery_file;
}
}
}
@@ -291,7 +291,7 @@ function media_gallery_view($node, $view_mode) {
// These JS settings are used by the "add media" link but some are also
// shared by the drag-and-drop code below.
- $instance = field_info_instance('node', 'media_gallery_media', $node->type);
+ $instance = field_info_instance('node', 'media_gallery_file', $node->type);
$token = drupal_get_token('media_gallery');
$gallery_js_settings = array(
'mediaGalleryAddImagesUrl' => url('media-gallery/add-images/' . $node->nid . '/' . $token),
@@ -321,21 +321,21 @@ function media_gallery_view($node, $view_mode) {
// rest from the node's field data, so that the field formatter doesn't waste
// time building the render structure for items that won't be shown.
if ($view_mode == 'teaser') {
- if (!empty($node->media_gallery_media[LANGUAGE_NONE])) {
+ if (!empty($node->media_gallery_file[LANGUAGE_NONE])) {
if (media_access('view')) {
- $first_item = array_shift($node->media_gallery_media[LANGUAGE_NONE]);
- $node->media_gallery_media[LANGUAGE_NONE] = array($first_item);
+ $first_item = array_shift($node->media_gallery_file[LANGUAGE_NONE]);
+ $node->media_gallery_file[LANGUAGE_NONE] = array($first_item);
}
else {
- $node->media_gallery_media[LANGUAGE_NONE] = array();
+ $node->media_gallery_file[LANGUAGE_NONE] = array();
}
}
}
// For the full display, implement pagination.
elseif ($view_mode == 'full' || $view_mode == 'media_gallery_block') {
$full = $view_mode == 'full' ? TRUE : FALSE;
- if (!empty($node->media_gallery_media) && media_access('view')) {
- $media = $node->media_gallery_media[LANGUAGE_NONE];
+ if (!empty($node->media_gallery_file) && media_access('view')) {
+ $media = $node->media_gallery_file[LANGUAGE_NONE];
}
else {
$media = array();
@@ -380,10 +380,10 @@ function media_gallery_view($node, $view_mode) {
// Field rendering requires sequential deltas, so re-key.
// @todo Open a Drupal core issue about this.
if ($media) {
- $node->media_gallery_media[LANGUAGE_NONE] = array_values($media);
+ $node->media_gallery_file[LANGUAGE_NONE] = array_values($media);
}
else {
- $node->media_gallery_media[LANGUAGE_NONE] = array();
+ $node->media_gallery_file[LANGUAGE_NONE] = array();
}
// Create a set of dummy links to media items that don't appear on this
@@ -603,7 +603,7 @@ function media_gallery_block_view($delta = '') {
$block['subject'] = NULL;
$block['content'] = '';
}
- elseif (empty($node->media_gallery_media_original) || !media_access('view')) {
+ elseif (empty($node->media_gallery_file_original) || !media_access('view')) {
// Bail out now if there won't be any media items to show.
$block['subject'] = check_plain($node->title);
$block['content'] = t('No content available.');
@@ -612,14 +612,14 @@ function media_gallery_block_view($delta = '') {
// Collect an array of file IDs associated with this gallery. For
// simplicity we will assume (here and below) that this is not a
// multilingual field. Also note that the node may have been loaded and
- // viewed elsewhere on the page, in which case the 'media_gallery_media'
+ // viewed elsewhere on the page, in which case the 'media_gallery_file'
// field was modified and does not contain what we want, so we have to go
// back to the original field value set in hook_node_load() instead, and
// also clone the node before changing it so our modifications do not
// affect other places where it might be being viewed.
$node = clone $node;
- $node->media_gallery_media = $node->media_gallery_media_original;
- $files = &$node->media_gallery_media[LANGUAGE_NONE];
+ $node->media_gallery_file = $node->media_gallery_file_original;
+ $files = &$node->media_gallery_file[LANGUAGE_NONE];
$gallery_fids = array();
foreach ($files as $file) {
$gallery_fids[] = _media_gallery_get_media_fid($file);
@@ -784,7 +784,7 @@ function _media_gallery_sort_by_recent($a, $b, $set_fid_order = NULL) {
/**
* Returns the number of files of each type attached to a media gallery node.
*/
-function media_gallery_get_media_type_count($node, $media_field = 'media_gallery_media') {
+function media_gallery_get_media_type_count($node, $media_field = 'media_gallery_file') {
$fids = media_gallery_get_file_ids($node, $media_field);
if (empty($fids)) {
return array();
@@ -802,7 +802,7 @@ function media_gallery_get_media_type_count($node, $media_field = 'media_gallery
/**
* Returns all file IDs attached to a media gallery node.
*/
-function media_gallery_get_file_ids($node, $media_field = 'media_gallery_media') {
+function media_gallery_get_file_ids($node, $media_field = 'media_gallery_file') {
$fids = array();
$media_items = _media_gallery_field_get_items('node', $node, $media_field);
if ($media_items !== FALSE) {
@@ -814,17 +814,17 @@ function media_gallery_get_file_ids($node, $media_field = 'media_gallery_media')
}
/**
- * media_gallery_media_original is not a field and therefore cannot be used by field_get_items.
+ * media_gallery_file_original is not a field and therefore cannot be used by field_get_items.
*/
function _media_gallery_field_get_items($entity_type, $entity, $field_name, $langcode = NULL) {
- if ($entity_type == 'node' && $field_name == 'media_gallery_media_original') {
- $media = $entity->media_gallery_media;
- $entity->media_gallery_media = $entity->media_gallery_media_original;
- $field_name = 'media_gallery_media';
+ if ($entity_type == 'node' && $field_name == 'media_gallery_file_original') {
+ $media = $entity->media_gallery_file;
+ $entity->media_gallery_file = $entity->media_gallery_file_original;
+ $field_name = 'media_gallery_file';
}
$items = field_get_items($entity_type, $entity, $field_name, $langcode);
if (isset($media)) {
- $entity->media_gallery_media = $media;
+ $entity->media_gallery_file = $media;
}
return $items;
}
@@ -858,7 +858,7 @@ function _media_gallery_get_media_fid($file) {
* The updated gallery node object.
*/
function media_gallery_remove_item_from_gallery($node, $file) {
- $items = &$node->media_gallery_media[LANGUAGE_NONE];
+ $items = &$node->media_gallery_file[LANGUAGE_NONE];
foreach ($items as $key => $item) {
if ($file->fid == _media_gallery_get_media_fid($item)) {
unset($items[$key]);
@@ -924,7 +924,7 @@ function media_gallery_form_media_gallery_node_form_alter(&$form, &$form_state)
_media_gallery_attach_form_resources($form);
// The UI for the multi value media field and the node weight is elsewhere.
- $form['media_gallery_media']['#access'] = FALSE;
+ $form['media_gallery_file']['#access'] = FALSE;
$form['media_gallery_weight']['#access'] = FALSE;
// Hiding this field because we only support a single collection at the moment.
@@ -1169,12 +1169,12 @@ function media_gallery_node_view_alter(&$build) {
}
// This is for when a gallery is being shown on its own, single gallery page.
elseif ($build['#bundle'] == 'media_gallery' && $build['#view_mode'] == 'full') {
- if (!empty($build['media_gallery_media'])) {
- foreach (element_children($build['media_gallery_media']) as $delta) {
+ if (!empty($build['media_gallery_file'])) {
+ foreach (element_children($build['media_gallery_file']) as $delta) {
// For each media item, add contextual links to the in-gallery-context
// tasks that can be performed on a media item.
- $fid = $build['media_gallery_media'][$delta]['#file']->fid;
- $build['media_gallery_media'][$delta]['#contextual_links']['media_gallery'] = array('media-gallery/detail', array($build['#node']->nid, $fid));
+ $fid = $build['media_gallery_file'][$delta]['#file']->fid;
+ $build['media_gallery_file'][$delta]['#contextual_links']['media_gallery'] = array('media-gallery/detail', array($build['#node']->nid, $fid));
}
}
_media_gallery_attach_css_resources($build);
@@ -1252,7 +1252,7 @@ function media_gallery_contextual_links_view_alter(&$element, $items) {
* Preprocess function for theme_field().
*/
function media_gallery_preprocess_field(&$variables, $hook) {
- if ($variables['element']['#field_name'] === 'media_gallery_media') {
+ if ($variables['element']['#field_name'] === 'media_gallery_file') {
$columns = 1;
switch ($variables['element']['#view_mode']) {
case 'media_gallery_block':
@@ -1467,7 +1467,7 @@ function media_gallery_edit_access($node) {
*/
function media_gallery_multiedit_access($node) {
if (media_gallery_edit_access($node) && media_access('edit')) {
- $media_items = field_get_items('node', $node, 'media_gallery_media');
+ $media_items = field_get_items('node', $node, 'media_gallery_file');
if ($media_items !== FALSE && count($media_items) > 0) {
return TRUE;
}
diff --git a/media_gallery.pages.inc b/media_gallery.pages.inc
index 161b8da..7c22c7e 100644
--- a/media_gallery.pages.inc
+++ b/media_gallery.pages.inc
@@ -236,7 +236,7 @@ function media_gallery_reorder_collection($collection, $order) {
* Reorder the media items in a gallery.
*/
function media_gallery_reorder_gallery($gallery, $order) {
- $media_field = $gallery->media_gallery_media[LANGUAGE_NONE];
+ $media_field = $gallery->media_gallery_file[LANGUAGE_NONE];
$offset = 0;
if (!empty($_POST['page'])) {
$page = array_pop(explode(',', $_POST['page']));
@@ -245,7 +245,7 @@ function media_gallery_reorder_gallery($gallery, $order) {
}
foreach ($order as $new_delta => $old_delta) {
- $gallery->media_gallery_media[LANGUAGE_NONE][$new_delta + $offset] = $media_field[$old_delta + $offset];
+ $gallery->media_gallery_file[LANGUAGE_NONE][$new_delta + $offset] = $media_field[$old_delta + $offset];
}
node_save($gallery);
return TRUE;
@@ -289,7 +289,7 @@ function media_gallery_add_images($node) {
$fids = $_POST['files'];
// Determine which file ids are already included in this gallery.
- $items = isset($node->media_gallery_media[LANGUAGE_NONE]) ? $node->media_gallery_media[LANGUAGE_NONE] : array();
+ $items = isset($node->media_gallery_file[LANGUAGE_NONE]) ? $node->media_gallery_file[LANGUAGE_NONE] : array();
foreach ($items as $item) {
$existing_fids[$item['fid']] = TRUE;
}
@@ -298,15 +298,15 @@ function media_gallery_add_images($node) {
foreach ($fids as $fid) {
// Only add a selected item if it isn't already in the gallery.
if (empty($existing_fids[$fid])) {
- $file = Array();
+ $file = array();
$file['fid'] = $fid;
- $file['title'] = NULL;
- $file['data'] = '';
+ $file['display'] = 1;
+ $file['description'] = '';
$items[] = $file;
}
}
- $node->media_gallery_media[LANGUAGE_NONE] = $items;
+ $node->media_gallery_file[LANGUAGE_NONE] = $items;
node_save($node);
drupal_json_output(array('result' => TRUE, 'items' => $items));
@@ -395,7 +395,7 @@ function media_gallery_media_page_multiedit($node) {
$rows = $node->media_gallery_rows[LANGUAGE_NONE][0]['value'];
$number_per_page = $columns * $rows;
$current_page = isset($_GET['page']) ? $_GET['page'] : 0;
- $items = array_slice($node->media_gallery_media[LANGUAGE_NONE], $current_page*$number_per_page, $number_per_page);
+ $items = array_slice($node->media_gallery_file[LANGUAGE_NONE], $current_page*$number_per_page, $number_per_page);
$fids = array();
foreach ($items as $item) {
$fids[] = $item['fid'];
diff --git a/media_gallery.theme.inc b/media_gallery.theme.inc
index ea64cbc..e70e3c3 100644
--- a/media_gallery.theme.inc
+++ b/media_gallery.theme.inc
@@ -50,9 +50,9 @@ function theme_media_gallery_teaser($variables) {
$element = $variables['element'];
$node = $element['#node'];
- if (isset($element['media_gallery_media'][0])) {
- $element['media_gallery_media'][0]['#theme'] = 'media_gallery_file_field_inline';
- $image = drupal_render($element['media_gallery_media'][0]);
+ if (isset($element['media_gallery_file'][0])) {
+ $element['media_gallery_file'][0]['#theme'] = 'media_gallery_file_field_inline';
+ $image = drupal_render($element['media_gallery_file'][0]);
}
else {
$image = theme('image', array('path' => drupal_get_path('module', 'media_gallery') . '/images/empty_gallery.png'));
@@ -76,7 +76,7 @@ function theme_media_gallery_teaser($variables) {
// Organize the file count by type. We only expect images and videos for
// now, so we put those first and group the others together into a general
// category at the end.
- $type_count = media_gallery_get_media_type_count($node, 'media_gallery_media_original');
+ $type_count = media_gallery_get_media_type_count($node, 'media_gallery_file_original');
$description = array();
if (isset($type_count['image'])) {
$count = $type_count['image'];
@@ -126,7 +126,7 @@ function template_preprocess_media_gallery_media_item_thumbnail(&$variables) {
// Add a class that is a more targeted version of what template_preprocess()
// automatically adds for this theme hook, to enable per-type (e.g., video vs.
// image) styling.
- $variables['classes_array'][] = drupal_html_class('media_gallery_media_item_thumbnail_' . $element['#file']->type);
+ $variables['classes_array'][] = drupal_html_class('media_gallery_file_item_thumbnail_' . $element['#file']->type);
// Add a class for the wrapper.
$variables['classes_array'][] = 'media-gallery-item-wrapper';
@@ -267,7 +267,7 @@ function theme_media_gallery_media_item_detail($variables) {
// moment. Is there a use-case for a media field (which is just a reference to
// a media entity) to be translatable?
$media_ids = array();
- foreach ($gallery_node->media_gallery_media[LANGUAGE_NONE] as $delta => $item) {
+ foreach ($gallery_node->media_gallery_file[LANGUAGE_NONE] as $delta => $item) {
$media_ids[] = _media_gallery_get_media_fid($item);
}
$media_ids = array_values(array_unique($media_ids));