If you are using UUID/Deploy to deploy content between sites, file fields will deploy correctly, but a file which is referenced in a textarea (using the media filter) does not, because UUID/Deploy does not know to look for it.

The standard way to fix this would be to implement UUID module's hooks in order swap the (site-specific) file ID that is stored in the textarea with the UUID on the source site, and then swap back again on the target site.

Comments

David_Rothstein’s picture

Status: Active » Needs review
StatusFileSize
new3.27 KB

The attached patch implements that solution.

It relies on code introduced in #1268116-36: WYSIWYG does not record file usage in order to work.

David_Rothstein’s picture

+    $new_ids = $entity_uuid_function('file', array($tag_info['fid']));
+    $new_id = reset($new_ids);
+    $tag_info['fid'] = $new_id;

Next time this patch is rerolled, it would be a good idea to change the first line above to if ($new_ids = $entity_uuid_function('file', array($tag_info['fid']))), since I don't think it's guaranteed that function will return anything.

Cap'taine Crochet’s picture

I'm trying to export entities to a features and cannot get files to be exported. I can see that the body field is updated with the file uuid, but the file itself is not a dependency, so it's not exported.
I had to implement hook_entity_dependencies then select files from file_usage that correspond to the current entity, and add them as dependencies.
Is it the intended way or we could move that hook to the patch? I could provide the updated patch if you need to.
Thanks

imp7’s picture

I am interested in your patch Cap'taine Crochet.
I want to be able to use media files inside wysiwyg text format like this in an install profile, this looks like the best approach, thanks.

ParisLiakos’s picture

Status: Needs review » Postponed
sylus’s picture

Status: Postponed » Active

Setting to active as #1268116 is now in

sylus’s picture

Cap'taine Crochet would you be able to show the work you did pushing file along as well?

sylus’s picture

Status: Active » Needs review
StatusFileSize
new3.29 KB

Attaching updated patch taking into account feedback from #1...

Additionally I was able based on #3 to attach a file to send over leveraging hook_entity_dependencies:

function hook_entity_dependencies($entity, $entity_type) {
  if ($entity_type == 'node') {
    $dependencies = array();
    $body = field_get_items('node', $entity, 'body');
    if ($body) {
      preg_match(MEDIA_TOKEN_REGEX, $body[0]['value'], $matches);
      $tag = $matches[0];
      $tag = str_replace(array('[[', ']]'), '', $tag);
      $tag_info = drupal_json_decode($tag);
      $dependencies[] = array('type' => 'file', 'id' => $tag_info['fid']);
    }
    return $dependencies;
  }
}
sylus’s picture

StatusFileSize
new3.29 KB

Corrected spacing

David_Rothstein’s picture

StatusFileSize
new3.74 KB

Here's a reroll adding a hook_entity_dependencies() implementation to force the referenced file to be deployed. (It's actually a little simpler than discussed above - we can use media_filter_parse_from_fields() to do the hard work.)

David_Rothstein’s picture

StatusFileSize
new3.74 KB

Fixing a typo in the code comment.

anfor’s picture

#11: media-filter-uuid-1578018-11.patch queued for re-testing.

skwashd’s picture

Status: Needs review » Needs work

I have a couple of sites deployed that accomplish this via the Embed Assets Field (EAF) module.

The disadvantage of the approach in this patch is that it bypasses the file usage count. Someone can delete all file/image field references to an asset and the it is deleted. The EAF approach means that the files are always properly referenced and so can't be deleted.

David_Rothstein’s picture

Status: Needs work » Needs review

What do you mean by "bypasses the file usage count" exactly? Isn't that already solved by #1268116: WYSIWYG does not record file usage (which was committed a while ago and which this patch relies on - see discussion above)?

aaron’s picture

#11: media-filter-uuid-1578018-11.patch queued for re-testing.

rosk0’s picture

Reroll + code style fixes.

Status: Needs review » Needs work

The last submitted patch, interdiff-1578018-16.patch, failed testing.

David_Rothstein’s picture

Looks like a good cleanup, except this one left off some words:

- * @return
- *   A string representing the JSON-encoded token, with the appropriate
- *   replacement between file IDs and UUIDs.
+ * @return string
+ *   A string representing the JSON-encoded token, with the appropriate.
  */
rosk0’s picture

StatusFileSize
new1.74 KB
new3.73 KB

Good catch. Fixed.

David_Rothstein’s picture

Status: Needs work » Needs review
aaron’s picture

Status: Needs review » Reviewed & tested by the community

This looks great.

aaron’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.