You are here

function ddf_load_dependencies in Dynamic dependent fields 7

Loads dependencies from the database.

4 calls to ddf_load_dependencies()
ddf_element_after_build in ./ddf.module
ddf_field_widget_options_select_form_alter in ./ddf.module
Implements hook_field_widget_WIDGET_TYPE_form_alter().
ddf_selector_element_process in ./ddf.module
ddf_update_access_callback in ./ddf.module
Access callback returning TRUE if the user can edit current entity.

File

./ddf.module, line 191

Code

function ddf_load_dependencies($entity_type, $bundle) {

  // Use the advanced drupal_static() pattern.
  static $dependencies = NULL;
  if (!isset($dependencies)) {
    $dependencies =& drupal_static(__FUNCTION__, array());
  }
  if (!isset($dependencies[$entity_type][$bundle])) {
    $dependencies[$entity_type][$bundle] = array();
    $result = db_select('ddf', 'd')
      ->fields('d', array(
      'field_name',
      'dependent_field_name',
      'data',
    ))
      ->condition('entity_type', $entity_type)
      ->condition('bundle', $bundle)
      ->execute();
    foreach ($result as $dependency) {
      if (strlen($dependency->data) > 0) {
        $dependency->data = unserialize($dependency->data);
      }
      $dependencies[$entity_type][$bundle][] = array(
        $dependency->field_name,
        $dependency->dependent_field_name,
        $dependency->data,
      );
    }
  }
  return $dependencies[$entity_type][$bundle];
}