I need to prevent users choosing a view mode for images inserted in wysiwyg, and use a standard default size for both wysiwyg preview and display. Ideally I'd prefer they don't ever see that dialog.

Any suggestions on best how to go about this would be appreciated.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gmclelland’s picture

John Pitcairn’s picture

Status: Active » Closed (duplicate)

Thanks - customizing/limiting the available styles would work well enough. Closing this as (near) duplicate.

chrisgross’s picture

I don't suppose you ever figured out how to suppress the view mode dialog entirely? I'm trying to figure it out but I'm having trouble. Limiting view modes is not quite enough for our needs.

chrisgross’s picture

It looks like this is tied to line 26 of js/media.format_form.js:

if (Drupal.settings.media_format_form.autosubmit) {
  $('.button.fake-ok').click();
}

This setting does not seem to exist. Perhaps we can have a setting to bypass the view mode selection either when there are no view modes available besides default, or perhaps via a module setting?

chrisgross’s picture

For anyone wondering, it looks like this will do the trick.

function custom_module_media_format_form_prepare_alter(&$form, &$form_state, $media) {
  $settings = array('autosubmit' => TRUE);
  drupal_add_js(array('media_format_form' => $settings), 'setting');
}

You may want to check the $media variable to determine when and where to use the autosubmit feature. I think I've read that the autosubmit may be legacy feature that could be removed in future versions. Can anyone confirm? If so, I think that would be a mistake and we should leave this in there as an option.

John Pitcairn’s picture

Looks like you can no longer autosubmit the format form in current dev, the code referenced in #4 is no longer present.

My use case has evolved somewhat due to client requests - we are now limiting the wysiwyg embedding to only include images already added to a field collection on the node. Some of these may be displayed automatically on the node, others are tagged as available wysiwyg insertion.

I have been asked to include image style selection, alt and title fields in the field collection on the node, and skip the wysiwyg format dialog entirely. They want editors to just choose and place an image from wysiwyg, with style/alt/title and other details only available to higher-level admins, and those only editable from the field collection. Then the embedded media tag should output the rendered field collection on node view, exactly the same as the field would render. Fun fun fun.

So re-opening this as a feature request.

John Pitcairn’s picture

Title: Skip wysiwyg image view mode dialog, set and use default? » Skip wysiwyg format dialog, set and use default values programmatically
Category: support » feature
Status: Closed (duplicate) » Closed (works as designed)

Something like this will get you there for current dev:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function mymodule_form_media_format_form_alter(&$form, $form_state) {
  $form['#attached']['js'][] = drupal_get_path('module', 'mymodule') . '/mymodule_media_format_form.js';
}
(function ($) {
  Drupal.behaviors.mymoduleMediaFormatForm = {
    attach: function (context, settings) {
      $(document).ready(function() {
        // Grab values etc from the current parent form fields and alter media format form values (roll your own code here).
        // Find the submit button and click it - code from media.format_form.js
        var buttons = $(parent.window.document.body).find('#mediaStyleSelector').parent('.ui-dialog').find('.ui-dialog-buttonpane button');
        buttons[0].click();
      });
    }
  }
})(jQuery);
John Pitcairn’s picture

Status: Closed (works as designed) » Active

Though a blank popup window is still briefly displayed after submitting from the media browser, and selecting the preview image in wysiwyg then clicking the media button also results in an overlay and blank popup window briefly displaying.

The hunt for a way to cleanly disable this continues...

John Pitcairn’s picture

Interim solution: the simple patch at #2000406: Pass dialog id to Drupal.media.popups.getDialogOptions() and add wrapper class (patch) adds a dialog-specific class to the media-wrapper, which can be used to totally suppress the auto-submitted dialog display via simple css:

div.media-wrapper-mediaStyleSelector,
div.media-wrapper-mediaStyleSelector + .ui-widget-overlay {
  display: none !important;
}
lslinnet’s picture

As you said being able to limit the choices would be an options, so though I would share usage of some of the supplied hooks.

https://gist.github.com/lslinnet/1ade60dc12907c42ab09

John Pitcairn’s picture

Thanks, I'm aware of the hooks. Unfortunately neither of those hooks will allow me to completely disable the format dialog. The format dialog is not a media browser plugin, and removing all the image styles won't help because there are still editable fields on the file entity (which I want). I need to suppress the entire dialog as per my use-case in #6.

Viresh Shah’s picture

It would take major refactoring to have this happen entirely programmatically so meanwhile we can use attached patch (media-skip_wysiwyg_format_dialog-1608172-12.patch) which does following things:

1. Adds on/off option to form admin/config/media/browser (default to true) which means it will always use defaults when embedding in a WYSIWYG.
2. Minor tweak in media.module to pass this variable to related javascript file (media.popups.js)
3. At JS side, it checks for variable and if it's true then it would skip WYSIWYG media format dialog.

Hope it helps!

SpadXIII’s picture

I wouldn't recommend using the patch in #12, because there is something easier, which works in a similar way: https://www.drupal.org/node/2460885

@Viresh Shah: your patch is also made incorrectly: the file paths are wrong: /docroot/sites/all/modules/contrib/media

Chris Matthews’s picture

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