Building on the new syntax used to pass arguments to exportable default_hooks, here is a patch that also allows the exportable to specify a different file for a specific function output. For example, placing some exportable functions in the component-specific file, while placing other functions (like alter hooks) into the main features.inc exported file.

Comments

mpotter’s picture

Status: Active » Needs review
StatusFileSize
new826 bytes

Here is the patch:

mpotter’s picture

Here is a new version that also prevents Features from creating an empty file when no content was written to it.

rypit’s picture

Status: Needs review » Reviewed & tested by the community

Tested this with patch on a myriad of features: created, diffed, updated and reverted exportables of context, boxes, views, menus, taxonomies and fields. All work as intended.

hefox’s picture

+++ b/features.export.inc
@@ -250,13 +250,19 @@ function features_export_render($export, $module_name, $reset = FALSE) {
   foreach ($code as $filename => $contents) {
-    $code[$filename] = "<?php\n/**\n * @file\n * {$module_name}.{$filename}.inc\n */\n\n". implode("\n\n", $contents) ."\n";
+    if (count($contents) > 0) {
+      $code[$filename] = "<?php\n/**\n * @file\n * {$module_name}.{$filename}.inc\n */\n\n". implode("\n\n", $contents) ."\n";
+    }
+    else {
+      unset($code[$filename]); // empty file
+    }

The if else could just be simplified as

$code = array_filter($code); before the foreach

Not sure if worth needs working it for that.

mpotter’s picture

Yep, good suggestion. Here is the new patch.

mpotter’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Committed to 7179946

mpotter’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev

  • mpotter committed 7179946 on 8.x-3.x
    Issue #1479068 by mpotter: Added Allow exportable code written to...
  • mpotter committed 8cb86ed on 8.x-3.x
    Issue #1479068 by mpotter: Added Allow exportable code written to...