diff --git a/js/media.js b/js/media.js index 9463def..9627669 100644 --- a/js/media.js +++ b/js/media.js @@ -71,14 +71,19 @@ Drupal.behaviors.mediaElement = { removeButton.hide(); } else { - if (editButton.length) { - editButton.attr('href', editButton.attr('href').replace(/media\/\d+\/edit/, 'media/' + fidField.val() + '/edit')); - // Re-process the edit link through CTools modal behaviors. - editButton.unbind('click'); - editButton.removeClass('ctools-use-modal-processed'); - // @todo Maybe add support for Drupal.detachBehaviors in Drupal.behaviors.ZZCToolsModal? - Drupal.attachBehaviors(editButton.parent(), Drupal.settings); - editButton.show(); + if (editButton.length) { + $.ajax({ + url: '/file/' + fidField.val() + '/edit', + success: function(data) { + editButton.attr('href', editButton.attr('href').replace(/media\/\d+\/edit/, 'media/' + fidField.val() + '/edit')); + // Re-process the edit link through CTools modal behaviors. + editButton.unbind('click'); + editButton.removeClass('ctools-use-modal-processed'); + // @todo Maybe add support for Drupal.detachBehaviors in Drupal.behaviors.ZZCToolsModal? + Drupal.attachBehaviors(editButton.parent(), Drupal.settings); + editButton.show(); + } + }); } removeButton.show(); } diff --git a/media.module b/media.module index 28b61d6..30db2d6 100644 --- a/media.module +++ b/media.module @@ -956,7 +956,7 @@ function media_element_process(&$element, &$form_state, $form) { ), ), '#weight' => 20, - '#access' => file_entity_access('update', $file), + '#access' => $file ? file_entity_access('update', $file) : TRUE, // only do perm check for existing files ); $element['remove'] = array( '#type' => 'link',