When another ctools modal is open and a user goes to edit a media field, the previously open modal is dismissed. This has been observed with custom ctools modals as well as ones within Panels (see below). The browse button doesn't seem to affect an open modal; just the edit button.

Panels

Original report. Observed on 7.x-2.0-alpha3
Brief version, saving edits returns you to the page that calls the pane edit modal, rather than returning you to the pane edit modal itself.
If I'm in a Panels modal and try to edit an image, saving the image bumps me out of the modal altogether instead of bringing me back to the pane editor.

Ideally when closing the Media edit modal it would return you to the pane edit modal it was called from, rather than the page that called the pane edit modal in the first place? I'm sure CTools can handle this, but I don't know how.

Details

It's a bit complex - it's using Panelizer and Fieldable Panel Panes (FPP)

  • I created an FPP widget called Orbit Carousel. I open a fieldable panel pane with images that uses the "media file selector" widget and Add some images. It returns me each time to the FPP edit screen.
  • Once the images are uploaded, I have "Select", "Edit" and "Remove" buttons
  • If I click on Select to change out the image, it brings up a the media browser modal and selects the image and returns to the FPP edit screen
  • If I click on Edit, it opens the modal to edit the image, but when I click save, it does not return me to the media browser modal, but brings me back to the main panel screen.

So to edit three images, you have to keep reopening the panels edit and if you do it before the first save, you lose everything.

I notice that the Select and Remove URLs are null paths that have a Javascript action attached to them like node/91/panelizer/page_manager/content# which is the URL of the page that launched the modal.

Edit on the other hand has a URL like media/286/edit/nojs?manualcrop[entity_type]=fieldable_panels_pane&manualcrop[bundle]=orbit_carousel&manualcrop[field_name]=field_orbit_images

These URLs are set in function media_element_process() in media.module with this code


  // @todo: Perhaps this language logic should be handled by JS since the state
  // changes on client side after choosing an item.
  $element['select'] = array(
    '#type' => 'link',
    '#href' => '',
    '#title' => t('Select'),
    '#attributes' => array('class' => array('button', 'launcher')),
    '#options' => array('fragment' => FALSE, 'external' => TRUE),
    '#weight' => 10,
  );
  // @todo Figure out how to update the preview image after the Edit modal is
  // closed.
  $element['edit'] = array(
    '#type' => 'link',
    '#href' => 'media/' . $fid . '/edit/nojs',
    '#title' => t('Edit'),
    '#attributes' => array(
      'class' => array(
        // Required for CTools modal to work.
        'ctools-use-modal', 'use-ajax',
        'ctools-modal-media-file-edit', 'button', 'edit',
      ),
    ),
    '#weight' => 20,
    '#access' => $file ? file_entity_access('update', $file) : TRUE, // only do perm check for existing files
  );
  $element['remove'] = array(
    '#type' => 'link',
    '#href' => '',
    '#title' => t('Remove'),
    '#attributes' => array('class' => array('button', 'remove')),
    '#options' => array('fragment' => FALSE, 'external' => TRUE),
    '#weight' => 30,
  );

Comments

ergophobe’s picture

Title: Edit modal closes entire panel rather than return to media browser scree » Edit modal closes entire panel rather than return to media browser screen
Category: Support request » Bug report
Issue summary: View changes

Changed to bug report, b/c I think the code in the proposed patch in #2192981: Restore media field widget edit button is the same with respect to this issue.

ergophobe’s picture

Issue summary: View changes
pianomansam’s picture

Title: Edit modal closes entire panel rather than return to media browser screen » Edit modal closes other open ctools modals
Version: 7.x-2.0-alpha3 » 7.x-2.0-alpha4
Issue summary: View changes
pianomansam’s picture

As ergophobe correctly observes, the edit button is a true menu item being opened in a true ctools modal. The problem this is that ctools only supports having one modal open at a time (#1470762: Opening a second modal window replaces first modal window). So the act of opening the second modal automatically closes the first. The solution to this is probably a way for the widget to know it's already in a ctools modal and to use it to load the edit form through AJAX instead of trying to open another modal.

heddn’s picture

brockfanning’s picture

It would be nice to have the Edit popup be non-Ctools, like the Browse popup is. But, that is probably much easier said than done. In the meantime, here is a quick sandbox module I wrote, that should hopefully alleviate the problem: https://www.drupal.org/sandbox/brockfanning/2761891
The idea is that you give the user the choice of whether to switch to the second modal as usual, or open it in a new tab.

czigor’s picture

We experience this when panels ipe opens a modal with a media widget and the image Edit button overwrites the modal with the image media form.

To solve this we did the following:


/**
 * Implements hook_field_widget_WIDGET_TYPE_form_alter().
 */
function MY_MODULE_field_widget_media_generic_form_alter(&$element, &$form_state, $context) {
  // When clicking the 'Edit' button of a media widget in a modal, it should
  // not try to open the media form in modal.
  if (strpos($_SERVER['REQUEST_URI'], 'panels/ajax/ipe/edit-pane/panelizer') !== FALSE ||
        strpos($_SERVER['REQUEST_URI'], 'panels/ajax/ipe/add-pane/panelizer') !== FALSE ||
        strpos($_SERVER['REQUEST_URI'], 'media/ajax') !== FALSE ) {
    foreach (element_children($element) as $delta) {
      if (is_numeric($delta)) {
        $element[$delta]['#process'][] = '_MY_MODULE_media_generic_widget_process';
      }
    }
  }
}

/**
 * Media form element process callback.
 */
function _MY_MODULE_media_generic_widget_process($element, $form_state, $form) {
  $url_parts = explode('/', $element['edit']['#href']);
  $element['edit']['#href'] = 'file/' . $url_parts[1] . '/edit';
  $element['edit']['#attributes']['class'] = [
    'button',
    'edit',
  ];
  $element['edit']['#attributes']['target'] = '_blank';
  return $element;
}


Chris Matthews’s picture

Version: 7.x-2.0-alpha4 » 7.x-2.x-dev
Status: Active » Closed (outdated)

Recent versions of media have resolved most of peoples concerns and is compatible with entity translation, multilingual and various advanced configurations. Due to the high volume of inactive and most often irrelevant issues we are Closing this as (outdated). If for whatever reason this issue is important to you AND you still have issues after checking the media recipe documentation, then let us know and we will review your concerns.

Otherwise, see the recipe documentation for how to configure media and for troubleshooting tips OR refer to the media_dev distribution if you want to see a working media setup.

As mentioned, feel free to make some noise in this issue if you still feel it is important to you or someone else.

Thanks,

Media team