Hi,

I'm currently working on a module that has the ability for users to upload files and reference the files in the configuration, and therefore I need the ability to have the referenced files exported when the configuration is exported.

I have put together a patch that adds said functionality by adding a new component hook (hook_features_export_assets()) which allows components to provide an array of files to be exported to [module_name]/assets/[component]/[filename].

Hope this is something that you consider as otherwise my module will not be able to provide Features export, and while it may not be something anyone else has specifically needed, there are definitely use cases where something like this is needed.

Cheers,
Deciphered.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Deciphered’s picture

After discussing with hefox in IRC this morning I have some possible changes that I will look at, mainly the ability for the module invoking the hook to be more specific about the location of the file being exported.

The approaches to this that I see as being viable are:

return array(
  'templates' => array(
    'file1.tpl.php' => 'location/to/file3.tpl.php',
    'location/to/file2.tpl.php',
    'node/file3.tpl.php' => 'location/to/file3_1.tpl.php',
  ),
  'images' => array(
    'file2.png' => 'location/to/file2.png',
    'example.png => 'location/to/file3.png',
  ),
);

Would create:
- [module_name]/assets/[component]/templates/file1.tpl.php
- [module_name]/assets/[component]/templates/file2.tpl.php
- [module_name]/assets/[component]/templates/node/file3.tpl.php
- [module_name]/assets/[component]/images/file2.png
- [module_name]/assets/[component]/images/example.png

Or:
- [module_name]/templates/[component]/file1.tpl.php
- [module_name]/templates/[component]/file2.tpl.php
- [module_name]/templates/[component]/node/file3.tpl.php
- [module_name]/images/[component]/file2.png
- [module_name]/images/[component]/example.png

However I do think that the second approach, while probably looking better, should probably have some restrictions on the directories. Maybe: templates, images, scripts, styles and misc?

Will look at updating the patch this afternoon.

Deciphered’s picture

FileSize
4.63 KB

Updated patch for above comments, went with: [module_name]/[type]/[component]/[file_destination] pattern.

Deciphered’s picture

FileSize
6.53 KB

Updated patch to change the hook to: hook_features_export_component_assets().

Also included includes/features.imagefield.inc to export the default image if defined.
Still need to figure out how to import the imagefield, may need a new hook.

hefox’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Needs review » Needs work
srjosh’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

Closing due to lack of activity.

hefox’s picture

Title: Add hook to export additional files/assets. » Allow export of additional files/assets.
Status: Closed (won't fix) » Needs work
FileSize
4.37 KB

Instead of adding a new hook, modified hook_features_export_render to allow adding new additional files to export that will be copied into the feature. It's.. messy cause there wasn't the a place to put it and it's against a stable version of features cause that's how I roll sometimes.

#2292813: Store the files in the feature instead of encoded data is corresponding default content issue that this is desired for.

hefox’s picture

Update patch to add hook so random ass files can be added outside the export render (like original ticket) and against -dev version.

hefox’s picture

Status: Needs work » Needs review
hefox’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
FileSize
6.38 KB

Lol 2.x

Fixing syntax error

Status: Needs review » Needs work

The last submitted patch, 9: 1064340-features-files-9.patch, failed testing.

hefox’s picture

Status: Needs work » Needs review
FileSize
6.38 KB

Status: Needs review » Needs work

The last submitted patch, 11: 1064340-features-files-10.patch, failed testing.

hefox’s picture

Status: Needs work » Needs review
FileSize
6.38 KB

sigh

ergonlogic’s picture

Over in #2411869: Include file_field files in exported Features, we're working on bundling files into uuid_features-based exports. This patch will greatly simplify that work. So far, I can say that the patch applies to 7.x-2.x with only a white-space warning. I've only had the chance to test hook_features_export_files(), but it works beautifully. I'll be running it through it's paces over the next couple days and will report back any findings.

ergonlogic’s picture

Status: Needs review » Reviewed & tested by the community

I just posted a patch over in #2411869: Include file_field files in exported Features that makes use of this patch's enhancements. It works great!

ergonlogic’s picture

Status: Reviewed & tested by the community » Needs work

Hmm, it appears to work very nicely for generating Features, but when downloading as a tarball, it renames all the included files to module_name.tar, just like the tarball itself.

ergonlogic’s picture

uuid_features now uses this functionality to package files attached to nodes, field_collections, etc. into exported features. With the exception of the bug I mentioned in #16, this patch works beautifully. I'm going to schedule some time to fix that, but I was wondering if there's anything else that'd hold up merging this?

hefox’s picture

Ah, I haven't used generate tarbal in... a long time. Other then that. don't know of any issues. Having multiple reviews, if possible, would be great also

MatthewHager’s picture

Status: Needs work » Reviewed & tested by the community

We've been using this patch in our platform for a while now and it works well. Would be nice if we could get this rolled into the next release.

mpotter’s picture

Status: Reviewed & tested by the community » Needs work

@MatthewHager: I don't see any fixes to this to address the issue raised in #16, so I think this still needs work. Can somebody confirm whether this is working or not when downloading the feature as a tarball that contains assets?

paulmartin84’s picture

The issue mentioned still exists, I have tracked it down to a simple typo in 1 location where it uses $filename when it should be $file_name

paulmartin84’s picture

Attached is a patch that fixes the issue mentioned in #16, I have also rerolled it against the latest dev.

paulmartin84’s picture

Status: Needs work » Needs review
attiks’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good and works great, small nitpick

+++ b/features.api.php
@@ -314,6 +315,26 @@ function hook_features_pipe_alter(&$pipe, $data, $export) {
+ *   file_content key to indicate the contents of the file. ¶

trailing white space

paulmartin84’s picture

Trailing white space has been removed, good spot @attiks

mpotter’s picture

Status: Reviewed & tested by the community » Fixed

Committed (with whitespace removed) to e8a1d8d.

  • mpotter committed e8a1d8d on 7.x-2.x authored by paulmartin84
    Issue #1064340 by hefox, Deciphered, paulmartin84: Allow export of...

Status: Fixed » Closed (fixed)

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