You are here

function globallink_config_features_export_render in GlobalLink Connect for Drupal 7.5

Same name and namespace in other branches
  1. 7.7 globallink.features.inc \globallink_config_features_export_render()
  2. 7.6 globallink.features.inc \globallink_config_features_export_render()

Implementation of hook_features_export_render. [component hook]

This hook will be invoked in order to export 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.

Parameters

string $module_name: The name of the feature module to be exported.

array $data: An array of machine name identifiers for the objects to be rendered.

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 value

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`.

File

./globallink.features.inc, line 108
Provides Features integration for the GlobalLink module to export settings and field configurations.

Code

function globallink_config_features_export_render($module, $data) {
  $code = array();
  foreach ($data as $component) {
    $data_row = array();
    $pos = strpos($component, '|');
    if ($pos) {
      $param = explode('|', $component);
      $data_row = db_query(" SELECT * FROM {globallink_field_config} WHERE content_type = :content_type AND field_name = :field_name  ", array(
        ':content_type' => $param[0],
        ':field_name' => $param[1],
      ))
        ->fetchAll();
    }
    if (count($data_row) > 0) {
      $code[$component] = get_object_vars($data_row[0]);
    }
    else {
      $result = db_query("SELECT * FROM {globallink_locale} WHERE locale_code = :code", array(
        ':code' => $component,
      ))
        ->fetchAll();
      if (count($result) > 0) {
        $code[$component] = get_object_vars($result[0]);
      }
      else {
        $code[$component] = variable_get($component);
      }
    }
  }
  $code = " return " . features_var_export($code, ' ') . ";";
  return array(
    'globallink_config_features_default_settings' => $code,
  );
}