Anyone diving into Media module and Styles for D7?

Events happening in the community are now at Drupal community events on www.drupal.org.
RobW's picture

A long story short, I've been poking my head into Media module for D7, and I like what I see. In the future this is definitely going to bring the user experience with media management a lot closer to Wordpress, which is good news for content creators, and media as entities is going to open up some really interesting ways to deal with multimedia content. BUT... (coding questions follow)

...Unfortunately Styles 7, which is the formatter for Media module, is still in alpha and is missing some really important UI and documentation, namely how to create your own file styles. In simplest usage this amounts to applying a custom image style to a media entity.

My question comes in here: have any of you been using Media and Styles in sandboxes or on your own projects, and have you been able to create custom file styles through a module? I've been digging through the Styles module, testing some code and printing arrays, but my expertise in Drupal stops right around the theming layer. This is the info I have gathered so far:

  • There's a hook provided at the end of http://drupal.org/node/1092444 which should tack on any image styles you've created onto the file styles ui,
  • and some people have been reporting success with it in http://drupal.org/node/1010958,
  • but I'm getting errors as posted in http://drupal.org/node/1010958#comment-4390490.
  • Line 268 to 289 in the Styles module describes the structure of a file style based on an image style, which gives slightly conflicting information compared to the code snippet on the docs page (param example is filefield instead of file, also missing one closing parenthesis if I am counting correctly).
  • When I dsm styles_default_presets('pretty much anything, including file, filefield, and empty'), I get an empty array.
  • When I try to add a hard coded preset with code like:
    <?php
    function custom_styles_default_presets() {
      
    $new_styles = array(
        
    'filefield' => array(
          
    'containers' => array(
            
    'imagefield' => array(
              
    'default preset' => 'tester',
              
    'presets' => array(
                
    'teststyle' => array(
                  
    'title' => '[node-title]',
                  
    'alt' => '',
                  
    'imagecache_preset' => 'teststyle',
                  
    'link' => '[node-path]',
                 ),
                
    'link_to_file' => array(
                  
    'title' => '[file-title-raw]',
                  
    'link' => '[file-path]',
                 ),
               ),
             ),
           ),
         ),
       );
      
    $orig_styles = styles_default_presets(); //Hoping no argument here gives the complete styles array. If it doesn't and I overwrite the whole $file_styles array, well at least something is happening. (Spoiler alert, nothing happens.)

    $file_styles = array_merge($new_styles, $orig_styles);

      return array(
       
    'file' => $file_styles
     
    );

    }
    ?>

    sort of a cobbling together of the in module comment and docs snippet, I get an error: Notice: Undefined index: containers in styles_default_presets() (line 315 of .../sites/all/modules/styles/styles.module).
  • So I tried removing the filefield key in the array, because of the array creation in the return statement, figured I was just off a level in the array structure. No errors! but no change in presets available.

Like I said, I am not a module developer, and I think this is about as far as I can go on my own. There are some small projects I'm working on that, if I could get this to work with some however messy stop-gap code, I would save a lot of time down the line by avoiding an eventual site revision replacing all image fields with media fields. Thanks to anyone who made it this far in the post, and if you have been playing with these two and have some thoughts, I would certainly appreciate it.

Comments

Thanks

cartagena's picture

Thanks for spelling it out--I am having the same issue but know much, much less than you do about the coding. I've searched and searched and your post is the only one I've found that addresses my issue. Although I've waded through all the media issues and like how it works, I've gone back to using Image field so that I can use my own styles when I set up views. Thanks again for getting the issue started.

No problem. I've made some

RobW's picture

No problem. I've made some progress but no custom styles yet. Because Media and Styles aren't in any sort of stable condition right now anything that we figure out is going to be a stop-gap, at which point we'll have to stop updating the modules until a stable, agreed upon method is included. To make matters worse, it's a real pain working with media in a sandbox, since it throws tons of errors if you disable it, and you can't uninstall it without permanently corrupting your db. Here are the threads to keep an eye on on drupal.org:

http://drupal.org/node/1010958
http://drupal.org/node/1126170
http://drupal.org/node/1086958

If I find a solution, I'll write up some docs and post a link back here. In the mean time, keep hacking.

Pittsburgh

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: