There may be instances when a web developer needs to transfer some database changes from one site to another. Moving the whole database may seem problematic or even become impossible given the new content in the database has appeared. The module Features is essential remedy for this problem. In this article, we will describe how to create your own feature, how to create your own items in the feature and how to export the parts of the site to the other site.
There are three values in the database (later on we will create them with a help of function variable_set()) which should be moved over to some other site.
With a help of the simple steps described below we will show you how to choose the values you need to export and the values you do not need.
1) Install the module Features.
2) Create your own module.
We will name our module idevels.
In the file idevels.module add hook_features_api(). With a help of this hook we inform about our feature and implement some parameters.
/** * Implements hook_features_api(). */ function idevels_features_api() { return array( 'values' => array( 'name' => t('Deploy values'), 'default_hook' => 'values_defaults', 'default_file' => FEATURES_DEFAULTS_INCLUDED, 'feature_source' => TRUE, 'file' => drupal_get_path('module', 'idevels') .'/idevels.features.inc', ), ); }
Now in the root of our module we create a file which was indicated in hook_features_api, in our case idevels.features.inc.
In this file, add hook hook_features_export_options().
At this point we have to take heed of some important moment. Hooks that are involved in the work of our feature should be given the name after the name of the feature, not after the module's name. In this particular case it would be values.
/** * Implements hook_features_export_options(). */ function values_features_export_options() { //only create variables variable_set('value1', 'value1'); variable_set('value2', 'value2'); variable_set('value3', 'value3'); return array( 'value1' => t('VALUE 1'), 'value2' => t('VALUE 2'), 'value3' => t('VALUE 3'), ); }