You are here

function freelinking_prepopulate_fields_from_page in Freelinking 6.3

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

Extract the specified array fields from the current or specified page. Build a l() 'query' array suitable for use by Prepopulate.

Parameters

$fields: Array of fields to process.

path: If NULL, the current page. Otherwise, lookup the path and use that page. (Path lookup not yet implemented)

See also

freelinking_prepopulate_list_fields(), l()

1 call to freelinking_prepopulate_fields_from_page()
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.utilities.inc, line 25
Freelinking Prepopulate Utilities

Code

function freelinking_prepopulate_fields_from_page($fields, $plugin = 'nodecreate', $path = NULL) {
  static $prepopulate;
  $query = array();
  $index = $plugin . serialize($fields);
  if (!$prepopulate[$index]) {
    $prepopulate[$index] = array_intersect_key(freelinking_prepopulate_list_fields($plugin), $fields);
  }
  if ($plugin == 'nodecreate' && arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) {
    $object = node_load(arg(1));
  }
  foreach ($prepopulate[$index] as $field => $definition) {
    switch ($field) {
      case 'og':
        $group = og_get_group_context();
        $query[$definition['prepopulate']] = $group->nid;
        break;
      case 'taxonomy':
        if (!$object->taxonomy) {
          break;
        }
        foreach ($object->taxonomy as $term) {
          $query[$definition['prepopulate'] . '[' . $term->vid . ']'] .= $term->name . ',';
        }
        break;
      case 'book':
        if ($node->book) {
          $query['parent'] = $object->book['mlid'];
        }
        break;
      default:
        if ($object->{$field}) {
          $query[$definition['prepopulate']] = $object->field;
        }
        break;
    }
  }
  return $query;
}