You are here

function freelinking_prepopulate_fields_from_array in Freelinking 6.3

Same name in this branch
  1. 6.3 modules/freelinking_prepopulate/freelinking_prepopulate.utilities.inc \freelinking_prepopulate_fields_from_array()
  2. 6.3 modules/freelinking_prepopulate/freelinking_prepopulate.api.php \freelinking_prepopulate_fields_from_array()
Same name and namespace in other branches
  1. 7.3 modules/freelinking_prepopulate/freelinking_prepopulate.utilities.inc \freelinking_prepopulate_fields_from_array()
  2. 7.3 modules/freelinking_prepopulate/freelinking_prepopulate.api.php \freelinking_prepopulate_fields_from_array()

Extract arguments for Prepopulate from the array. Build a 'query' array suitable for use by Prepopulate.

Parameters

$target : array: Array build from syntax defining arguments for use by the plugin. Any elements recognized by freelinking_prepopulate will be used.

See also

freelinking_prepopulate_list_fields(), l()

1 call to freelinking_prepopulate_fields_from_array()
freelinking_prepopulate_node_callback in modules/freelinking_prepopulate/freelinking_prepopulate.module
Node Create replacement callback Ultimate default: [[create:pagetitle]] => <a href="node/add/page?edit[title]=pagetitle>pagetitle</a>

File

modules/freelinking_prepopulate/freelinking_prepopulate.api.php, line 77
Freelinking Prepopulate API

Code

function freelinking_prepopulate_fields_from_array($plugin, $target) {
  $query = array();
  $prepopulate = array_intersect_key(freelinking_prepopulate_list_fields($plugin), $target);
  foreach ($prepopulate as $field => $values) {

    // If it's an organic group, break the groups out to separate values.
    if ($field == 'og') {
      $query[$values['prepopulate']] = $target[$field];
    }
    elseif ($field == 'taxonomy') {
      if (!strpos($target[$field], ':')) {
        $query[$values['prepopulate'] . '[1]'] = $target[$field];
        continue;
      }
      list($vocab, $terms) = explode(':', $target[$field]);
      if (is_int($vocab)) {
        $query[$values['prepopulate'] . '[' . $vocab . ']'] = $terms;
      }
      else {
        $query[$values['prepopulate'] . '[1]'] = $terms;
      }
    }
    else {
      $query[$values['prepopuplate']] = $target[$field];
    }
  }
  return $query;
}