I would like to see the code for the views plugin be changed to pass back a form rather than the raw HTML that it is now. This actually would go for all plugins in the future. There are a few advantages that I see to this:
* allows us to use standard drupal form functions (particularly validation and alter functions) more predictably
* will let us cleanup some of the very difficult JS that is currently in place
* standardize the media browser on forms which will make it easier for new implementors to follow the pattern

After working on http://drupal.org/node/1016376 it seems to me that it will be much easier to implement a standard file type validation for specific drupal fields if we can do a form alter on the plugin in a standard way. As it stands I'm not sure that it will be easy to do without adding more convoluted code.

The attached patch is a proof of concept. It renders the view output as links over checkboxes and passes those back. There is an error where the file is being stored as a JS value. I think this has to do with the fake submit buttons but I haven't investigated too much further. If there is interest in taking this route I think we could fairly quickly cleanup the existing code. This might shed some light in the dark corners of the legacy code....

CommentFileSizeAuthor
#1 plugin_form.diff5.55 KBarthurf
views_form.diff5.56 KBarthurf

Comments

arthurf’s picture

StatusFileSize
new5.55 KB

Here's a slightly more abstracted version. Still does not resolve the error on picking the file.

elijah lynn’s picture

dave reid’s picture

Status: Active » Needs work

Some quick initial reviews although I think this still holds some promise.

  1. +++ b/includes/MediaBrowserView.inc
    @@ -43,13 +43,18 @@ class MediaBrowserView extends MediaBrowserPlugin {
    +      // Load all the files
    +      foreach ($results as $result) {
    +        $file = file_load($result->fid);
    +        $files[$file->fid] = $file;
    +      }
    +      $build['form'] = drupal_get_form('media_browser_plugin_form', $files);
    

    We should have this use file_load_multiple()

  2. +++ b/includes/media.browser.inc
    @@ -430,3 +430,71 @@ function media_browser_build_media_item($file) {
    +  foreach ($form_state['values']['views_files'] as $fid) {
    +    if (! empty($fid)) {
    +      $form_state['file'] = file_load($fid);
    +    }
    +  }
    

    If we did a file_load() and passed them into drupal_get_form() shouldn't they still be available in $form_state['build info']['args'] or something similar?

chris matthews’s picture

Status: Needs work » Closed (outdated)

Closing this issue as outdated. However, if you think this issue is still important, please let us know and we will gladly re-open it for review.
sincerely,
- the Drupal Media Team