I've written a script which fetches data from a REST API and uses it to update a field in a node. The website is multilingual (Canada English, Canada French, Australia English and US English) with US English as the default language. When I run the script with drush, it updates field_gj_metro_id with the correct value from the REST API, but for all nodes with languages other than US English, it deletes the node title.

What am I missing in my script that would take care of the language settings so that the titles will be unaffected?

function fetch_metros() {
  return gj_api_request('GetMetroList', $arguments = array());

$metros = array();
$metros = fetch_metros();
foreach ($metros as $metro) {
  $query = new EntityFieldQuery();
    ->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'gj_locations')
    ->propertyCondition('status', 1)
    ->propertyCondition('title', $metro['metroName'])
    ->propertyOrderBy('created', 'DESC')
    ->fieldCondition('field_display_in_listing', 'value', TRUE);
  $result = $query->execute();

  if (!empty($result)) {
    $nids = array_keys($result['node']);
    $node = node_load($nids[0]);
    $node_wrapper = entity_metadata_wrapper('node', $node);
  • not fully related to your question 1) set the revision flag may help on the node if its not set on the content type 2) you could try $node->wrapper->title->set( $node_wrapper->title); and then set the language flag too ...
    – tenken
    Commented Aug 20, 2014 at 23:10
  • Revision flag is already set on the content type. I tried various methods of setting the title but nothing worked. The node retains all of it's existing data, except for the title. Commented Aug 22, 2014 at 19:42
  • I ran into a similar issue with title values being blanked out (also I was using the Title module). I needed to call entity_get_controller('node')->resetCache($nids) before I saved the entities api.drupal.org/api/drupal/includes%21entity.inc/function/…. It might not be what you need but worth a shot? Entity Translation is... somewhat chaotic. Commented Aug 24, 2014 at 22:15

1 Answer 1


I tried calling resetCache but the problem persisted. In the end I created a page for each language and used the PHP filter to add the script to the page. By switching to each language, setting the value of propertyCondition('language','') to the loaded language and loading the corresponding page, I was able to import the metroIDs and update the pages, one language at a time, without deleting the titles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.