Gizra / og

https://www.drupal.org/project/og
92 stars 133 forks source link

When using OG with Scald, Scald's multiple upload functionality breaks OG widget. #114

Open sh0rtwave opened 8 years ago

sh0rtwave commented 8 years ago

When using Scald's multiple upload functionality when creating new Media Atoms, Organic Groups fields will only appear on the first item in the upload.

This is because in includes/og-field.inc, in the function og_field_widget_form(), at the time that each Scald atom comes through the function, it doesn't have a entity ID. It has a scald-assigned "base_id" only.

See the following code from og_field_widget_form():

// Cache the processed entity, to make sure we call the widget only once.
  $cache = &drupal_static(__FUNCTION__, array());
  list($id, , $bundle) = entity_extract_ids($entity_type, $entity);
  $field_name = $field['field_name'];

  $identifier = $field_name . ':' . $entity_type . ':' . $bundle . ':' . $id;
  if (isset($cache[$identifier])) {
    return array();
  }
  $cache[$identifier] = TRUE;

At the point where the $identifier is tested against the cache, since the $id is returned as NULL from entity_extract_ids (because the atoms haven't actually been saved), the $identifier will be the exact same string for all forms that need to be created.

This is a pretty obscure bug, since most people won't encounter this (and it happens to work just fine for most people, since most entities are usually created one at a time) but it does cause issues with things like Scald.

sh0rtwave commented 8 years ago

Fix for situation when an entity has no id (e.g. it's new, and hasn't been saved yet). og-widget-breaks-onscald-multi-upload-id-fix-114.patch.txt

scotself commented 8 years ago

+1 for this. Scald is a fantastic media management module and the plupload option for creating multiple atoms at once is indispensable. The widget should not natively assume that there is only one form on the page and allow for multiples and also for entities still in the process of being created.