Skip to content

Instantly share code, notes, and snippets.

@mazewei
Created March 15, 2014 14:28
Show Gist options
  • Save mazewei/9568147 to your computer and use it in GitHub Desktop.
Save mazewei/9568147 to your computer and use it in GitHub Desktop.
extension for drupal module DrupalGap. Manipulate the webservice to submit also term names, not only term ids
//TODO backend for configure taxonomy ref fields
/**
* Implements hook_services_request_postprocess_alter().
*/
function bdi_tax_tid_services_request_postprocess_alter($controller, $args, &$result) {
if ($controller['callback'] === '_node_resource_retrieve') {
$fieldnames = array();
//your fieldnames here
$fieldnames = array(field_herausgeber_autor,field_keywords,field_zeitschriftentitel);
foreach ($result as $key => $value) {
foreach($fieldnames as $fieldnames_key => $fieldnames_value) {
$current_field_name = $fieldnames_value;
if ($key == $fieldnames_value) {
$keywords = $value;
foreach ($keywords['und'] as $key_term => $value_term) {
$termname = taxonomy_term_load($value_term['tid']);
//dynamically
if(!isset($add_to_array)) {
$add_to_array = array();
}
$add_to_array[$key]['und'][$key_term]['value'] = $termname->name;
$add_to_array[$key]['und'][$key_term]['tid'] = $termname->tid;
}
}
}
}
foreach ($add_to_array as $add_to_array_key => $add_to_array_value) {
foreach($result as $key2 => $value2) {
if($key2 == $add_to_array_key) {
$result->$key2 = $add_to_array_value;
}
}
}
}
}
@signalpoint
Copy link

@mazewei and @ice432cube, this feature now works in the latest development snapshots of the DrupalGap module and SDK. Otherwise it will become available in the next recommended releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment