You are here

function configuration_build_context in Configuration Management 6

Build a context object given a normal php data object

Parameters

$obj: A reference to the data object needing context

Return value

The context object for the data object

3 calls to configuration_build_context()
configuration_check_context in ./configuration.module
Check and fix the integrity of the context object in case changes were made to the data
configuration_initiate in ./configuration.module
Initialize whats needed to execute a configuration.
configuration_sync_data_form in ./configuration.module
Based on a form api array, make automatic modifications to the form submission data.

File

./configuration.module, line 1572
Provide a unified method for defining site configurations abstracted from their data format. Various data formats should be supported via a plugin architecture such as XML, YAML, JSON, PHP

Code

function configuration_build_context(&$obj, $key = null, $trace = array(), &$parent = null) {
  $context = (object) array(
    'trace' => $trace,
    'key' => $key,
    'item' => &$obj,
    'parent' => $parent,
    'children' => array(),
  );
  $refs = array(
    &$context,
  );
  while (!empty($refs)) {
    $ref =& $refs[0];
    $parent =& $ref->item;
    array_splice($refs, 0, 1);
    if (is_array($parent) && !empty($parent)) {
      $i = 0;
      foreach ($parent as $index => &$child) {

        // TODO possible optimizations can be done here (with the parent trace)
        $ref->children[$i] = (object) array(
          'trace' => configuration_trace_context($ref),
          'key' => $index,
          'item' => &$child,
          'parent' => &$ref,
          'children' => array(),
        );
        array_unshift($refs, '');
        $refs[0] =& $ref->children[$i++];
      }
    }
  }
  return $context;
}