I all,

I'm not sure if this is a bug or a feature request, but I've noticed this:

Speaking of (module) media images inserted INLINE in a text body using wysiwyg, cropping options are only available on first upload of the image (on step 2 of file entity wizard).

If you then try to edit the same image (selecting it in the wysiwyg area and then clicking on the media browser button in the wysiwyg toolbar) no cropping options area available in the "popup" (where at the moment I can only change alt and title fields and view modes for this file).

How can this be resolved?

Thank you very much

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MXT’s picture

I've successfully obtained cropping options and manualcrop stuff within the "edit" popup in mediabrowser adding this in the manualcrop module:

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Provides integration with the File Entity (and Media) module by adding the
 * crop functionality to the file edit form opened in media browser popup widget from a wysiwyg.
 */
function manualcrop_form_media_format_form_alter(&$form, &$form_state) {
  if (user_access('use manualcrop') && $form['#media']->type == 'image') {
    // Get the field instance information.
    $instance_info = array();
    
    // WHAT KIND OF STUFF I HAVE TO WRITE HERE TO RETRIEVE $instance_info DATA?

    // Process the form.
    _manualcrop_process_file_entity_form($form, $form_state, $instance_info, $form['#media']);
  }
}

But when I use the cropping tool to crop the image the new crop is not saved on form submit.

Why?

I think something in the above code is missing: for example I don't know how to populate the $instance_info array with correct values.

Please help me!

Thank you very much

erykmynn’s picture

We have had the same problem. Here is a module I wrote integrated manual crop very nicely with the latest 7.x-2.x builds of Media Module. If you are a few verions back on media module, I think it will work with just a change to a few callback namespaces. I would be very happy to patch into Manualcrop any parts of this that would serve the projects needs. Really overrides one of Manuacrops hooks to work with the newer version of Media and also makes sure to respect Media Wysiwyg View Modes restrictions.

MXT’s picture

Hi erykmynn and thank you for sharing your code!

I've tried to install your module but I'm receiving the following error after uploading a file through media browser widget called from inside a wysiwyg editor:

Fatal error: Call to undefined function media_wysiwyg_get_wysiwyg_allowed_view_modes() in /var/www/mysite/sites/all/modules/contrib/manualcrop_media_wysiwyg/manualcrop_media_wysiwyg.module on line 38

I'm using very recent version of both media and manual crop:

  • manualcrop 7.x-1.4+81-dev (2013-Nov-17)
  • media 7.x-2.0-alpha3+12-dev (2013-Nov-13)

Is your module updated to these latest versions?

Thank you very much for your work!

MXT’s picture

In your module, line 38, if you change:

$allowed_modes = media_wysiwyg_get_wysiwyg_allowed_view_modes($file);

with:
$allowed_modes = media_get_wysiwyg_allowed_view_modes($file);

the error disappear, and media popup shows only one crop option, but I have enabled 3 view modes for wysiwyg, so I think there is something to adjust now, I don' know.

My original issues is still not resolved (that part of code is commented in your module)

Thank you in any case!

fibigerg’s picture

Subscribe. I need this feature or something like this. I need my editors to be able to change crops by simple clicking edit button in wysiwyg. I have 4 image views for WYSIWYG with 3 crops.

I will test your module tomorrow and write down results.

erykmynn’s picture

Here is a newer version. See also https://drupal.org/node/2102745 which is closely related.

TwoD’s picture

The reason you're not seeing any cropping options in the dialog which pops up when you have selected an already inserted image is that the Media module only shows options for things (attributes/fields/file view mode) which will be stored in the [[media]] "macro" inserted into the content. These values are used to override the values stored in a media file's File entity during rendering, or at least they should be used that way - there are currently issues with doing that in some cases.

The reason the module posted above needs to insert a separate "Save recropped styles" button is that no #submit handlers will be run when the "Save" button is clicked, because the form is never submitted to the server. The Media module's popup code just grabs the value from the view mode selector, and any other element in the options fieldset, serialize them to a JSON string and put them in the macro tag.

Even if the crop tool was put into the options fieldset, the new crop information would not reach the File entity, it'd just sit in the [[media]] macro in the content and be discarded during rendering - at which point it'd be too late, or too much work, to re-generate the image styles. By "too much work", I mean that every piece of content could have unique crop data for every inserted image so you could not rely on the image style code to automatically generate the styles as they are requested.

One could maybe hook into the popup code, extract the crop data from the dialog before it closes and make an AJAX request which stores the new crop data in the File entity, but I have not tested that. It sounds a bit fragile if the Media module ever changes how the dialog works...

erykmynn’s picture

I have sandboxed my solution:
https://www.drupal.org/sandbox/erykmynn/2443015

However, I think the issue below may have solved the problem in dev (i have not personally tested it)
#1665130: Widget options for Media 2.x WYSIWYG integration

dqd’s picture

Chris Charlton’s picture

Still an issue in dev?