When I upload images using the Media toolbar button (CKEditor) I get options to format the image - a drop down with options Link, Preview, Large and Original. Where are these defined? Are they related to the Media module -> Image Styles options? If I change setting in Image Styles I don't see anything reflected here. How can I change these formats? Thanks.

Comments

TwoD’s picture

Project: Wysiwyg » D7 Media
Version: 7.x-2.1 » 7.x-1.0-beta5
Component: Editor - CKEditor » WYSIWYG integration

Yes, I think the button/dialog you are referring to are controlled by Media module.
Moving to their queue. Please change the version if my guess is incorrect.

mattcooper’s picture

Anyone got any thoughts on this?

The seemingly simple objective of having a user friendly image uploader for a rich text field seems impossible at the moment, how does everyone else do it?

vefverksmidja’s picture

I have added this feature into media because I wanted to be able to choose from the image styles when formatting the image (adding into body) in CKEditor

in media/includes folder find the
media.filter.inc

in the media format form there you will find a foreach ($view_modes as $view_mode => $view_mode_info) {
What I did was put before it an if condition checking if the file type was image or not if it was image then I wen to the else

So the end result looks like this

<?php
function media_format_form($form, $form_state, $file) {
  $form = array();
  $form['#media'] = $file;

  $entity_info = entity_get_info('file');
  
  $view_modes = $entity_info['view modes'];
  drupal_alter('media_wysiwyg_allowed_view_modes', $view_modes, $file);

  $options = array();
  if ($file->type != 'image') {
    foreach ($view_modes as $view_mode => $view_mode_info) {
      // Don't present the user with an option to choose a view mode in which the
      // file is hidden.
      $extra_fields = field_extra_fields_get_display('file', $file->type, $view_mode);
      if (!$extra_fields['file']['visible']) {
        continue;
      }

      //@TODO: Display more verbose information about which formatter and what it does.
      $options[$view_mode] = $view_mode_info['label'];
      $element = media_get_file_without_label($file, $view_mode, array('wysiwyg' => TRUE));
      
      // Make a pretty name out of this.
      $formats[$view_mode] = drupal_render($element);
    }
  }
  else {
    foreach (image_styles() as $view_mode => $view_mode_info) {
      // Don't present the user with an option to choose a view mode in which the
      // file is hidden.
      $extra_fields = field_extra_fields_get_display('file', $file->type, $view_mode);
      if (!$extra_fields['file']['visible']) {
        continue;
      }

      $options[$view_mode] = $view_mode;
      if ($view_mode_info['name'] == $view_mode) {
          $effect = $view_mode_info['effects'];
      }
      $key = array_keys($effect);
      $key = $key[0];
      $width = $effect[$key]['data']['width'];
      $height = $effect[$key]['data']['height'];
      $variables = array(
        'style_name' => $view_mode,
        'path' => $file->filepath.'/'.$file->filename,   
        'alt' => $file->name,
        'width' => $width,
        'height' => $height,
      );
        
      $mynd = theme_image_style($variables);      
      
      // Make a pretty name out of this.
      $formats[$view_mode] = $mynd;

    }
  }
?> 

Hope this helps someone to be able to use this or take it step further and make it better.

tsvenson’s picture

Status: Active » Closed (fixed)

Closing due to no activity for a long time. Feel free to reopen with updated info if issue still remains.

Jboo’s picture

Version: 7.x-1.0-beta5 » 7.x-2.0-unstable6
Status: Closed (fixed) » Active

I've used the code to alter the media.filter.inc file and the new styles appear as suggested. However, I have a couple of issues...

I have these errors:

Notice: Undefined property: stdClass::$filepath in media_format_form() (line 299 of /home/j/public_html/site.com/sites/all/modules/media/includes/media.filter.inc).
Notice: Undefined property: stdClass::$name in media_format_form() (line 300 of /home/j/public_html/site.com/sites/all/modules/media/includes/media.filter.inc).

Also, the image appears correctly in preview, however only the media module default image appears when viewing the node and not the image that's been uploaded.

Could anyone point out why I'm getting the error and issue?

Thanks for any help.

Devin Carlson’s picture

Status: Active » Closed (works as designed)

The format form allows you to select which view mode the file being embedded is displayed with. This is by design. If you want to present users with a variety of image sizes to choose from, create new file view modes using Entity view modes or Display Suite and assign them the image formatter with different image styles applied.