array( 'default_hook' => 'mycomponent_defaults', 'default_file' => FEATURES_DEFAULTS_INCLUDED, 'features_source' => TRUE, 'file' => drupal_get_path('module', 'mycomponent') .'/mycomponent.features.inc', ), ); } /** * Component hook. The hook should be implemented using the name ot the * component, not the module, eg. [component]_features_export() rather than * [module]_features_export(). * * Process the export array for a given component. Implementations of this hook * have three key tasks: * * 1. Determine module dependencies for any of the components passed to it * e.g. the views implementation iterates over each views' handlers and * plugins to determine which modules need to be added as dependencies. * * 2. Correctly add components to the export array. In general this is usually * adding all of the items in $data to $export['features']['my_key'], but * can become more complicated if components are shared between features * or modules. * * 3. Delegating further detection and export tasks to related or derivative * components. * * Each export processor can kickoff further export processors by returning a * keyed array (aka the "pipe") where the key is the next export processor hook * to call and the value is an array to be passed to that processor's $data * argument. This allows an export process to start simply at a few objects: * * [context] * * And then branch out, delegating each component to its appropriate hook: * * [context]--------+------------+ * | | | * [node] [block] [views] * | * [CCK] * | * [imagecache] * * @param array $data * An array of machine names for the component in question to be exported. * @param array &$export * By reference. An array of all components to be exported with a given * feature. Component objects that should be exported should be added to * this array. * @param string $module_name * The name of the feature module to be generated. * @return array * The pipe array of further processors that should be called. */ function hook_features_export($data, &$export, $module_name) { // The following is the simplest implementation of a straight object export // with no further export processors called. foreach ($data as $component) { $export['mycomponent'][$component] = $component; } return array(); } /** * Component hook. The hook should be implemented using the name ot the * component, not the module, eg. [component]_features_export() rather than * [module]_features_export(). * * List all objects for a component that may be exported. * * @return array * A keyed array of items, suitable for use with a FormAPI select or * checkboxes element. */ function hook_features_export_options() { $options = array(); foreach (mycomponent_load() as $mycomponent) { $options[$mycomponent->name] = $mycomponent->title; } return $options; } /** * Component hook. The hook should be implemented using the name ot the * component, not the module, eg. [component]_features_export() rather than * [module]_features_export(). * * Render one or more component objects to code. * * @param string $module_name * The name of the feature module to be exported. * @param array $data * An array of machine name identifiers for the objects to be rendered. * @param array $export * The full export array of the current feature being exported. This is only * passed when hook_features_export_render() is invoked for an actual feature * update or recreate, not during state checks or other operations. * @return array * An associative array of rendered PHP code where the key is the name of the * hook that should wrap the PHP code. The hook should not include the name * of the module, e.g. the key for `hook_example` should simply be `example`. */ function hook_features_export_render($module_name, $data, $export = NULL) { $code = array(); $code[] = '$mycomponents = array();'; foreach ($data as $name) { $code[] = " \$mycomponents['{$name}'] = " . features_var_export(mycomponent_load($name)) .";"; } $code[] = "return \$mycomponents;"; $code = implode("\n", $mycomponents); return array('mycomponent_defaults' => $code); } /** * Component hook. The hook should be implemented using the name ot the * component, not the module, eg. [component]_features_export() rather than * [module]_features_export(). * * Revert all component objects for a given feature module. * * @param string $module_name * The name of the feature module whose components should be reverted. * @return boolean * TRUE or FALSE for whether the components were successfully reverted. */ function hook_features_export_revert($module_name) { $mycomponents = module_invoke_all($module_name, 'mycomponent_defaults'); if (!empty($$mycomponents)) { foreach ($mycomponents as $mycomponent) { mycomponent_delete($mycomponent); } } } /** * Component hook. The hook should be implemented using the name ot the * component, not the module, eg. [component]_features_export() rather than * [module]_features_export(). * * Rebuild all component objects for a given feature module. Should only be * implemented for 'faux-exportable' components. * * This hook is called at points where Features determines that it is safe * (ie. the feature is in state `FEATURES_REBUILDABLE`) for your module to * replace objects in the database with defaults that you collect from your * own defaults hook. See API.txt for how Features determines whether a * rebuild of components is possible. * * @param string $module_name * The name of the feature module whose components should be rebuilt. */ function hook_features_export_rebuild($module_name) { $mycomponents = module_invoke_all($module_name, 'mycomponent_defaults'); if (!empty($$mycomponents)) { foreach ($mycomponents as $mycomponent) { mycomponent_save($mycomponent); } } } /** * Alter the final export array just prior to the rendering of defaults. Allows * modules a final say in altering what component objects are exported. * * @param array &$export * By reference. An array of all components to be exported with a given * feature. * @param array $module_name * The name of the feature module to be generated. */ function hook_features_export_alter(&$export, $module_name) { // Example: do not allow the page content type to be exported, ever. if (!empty($export['node']['page'])) { unset($export['node']['page']); } } /** * Alter the pipe array for a given component. This hook should be implemented * with the name of the component type in place of `component` in the function * name, e.g. `features_pipe_views_alter()` will alter the pipe for the Views * component. * * @param array &$pipe * By reference. The pipe array of further processors that should be called. * @param array $data * An array of machine names for the component in question to be exported. * @param array &$export * By reference. An array of all components to be exported with a given * feature. * @param string $module_name * The name of the feature module to be generated. */ function hook_features_pipe_component_alter(&$pipe, $data, $export, $module_name) { }