<?php
/**
 * @file
 * VS Variables feature module - main module file.
 */

/**
 * Custom hook_feature_info() to return details about this feature module.
 *
 * @return array
 *   Array with the following keys:
 *   - name: human readable name of the feature module,
 *   - description: human readable description of the feature module.
 */
function virtual_site_variables_feature_info() {
  return array(
    'virtual_site_variables_feature' => array(
      'name' => t('Variables'),
      'description' => t('Override any Drupal variable for this virtual site.'),
    ),
  );
}

/**
 * Form constructor for the feature module settings form.
 *
 * @see virtual_site_menu()
 * @see virtual_site_variables_feature_validate()
 *
 * @ingroup forms
 */
function virtual_site_variables_feature_form($context) {
  $form = array();

  $form['virtual_site_variables_feature'] = array(
    '#tree' => TRUE,
  );
  $form['virtual_site_variables_feature']['variables'] = array(
    '#type' => 'textarea',
    '#title' => t('Variables to override'),
    '#description' => t("Enter variables using any of the following syntax:<br /><br />key = value<br />key = \"value\"<br />key = 'value'<br />key = \"multi-line<br />value\"<br />key = 'multi-line<br />value'<br />key<br />=<br />'value'"),
    '#default_value' => isset($context['variables']) ? $context['variables'] : '',
  );

  return $form;
}

/**
 * Form validation handler for virtual_site_variables_feature_form().
 */
function virtual_site_variables_feature_validate($form, &$form_state) {
}

/**
 * Custom feature handler.
 * Modifies global variable $conf according to the context.
 *
 * @param array $context
 *   Context of the virtual site.
 */
function virtual_site_variables_feature($context) {
  global $conf;

  foreach (drupal_parse_info_format($context['variables']) as $name => $value) {
    $conf[$name] = $value;
  }
}
