translation_entity.admin.inc 24.5 KB
Newer Older
1 2 3 4 5 6 7 8
<?php

/**
 * @file
 * The entity translation administration forms.
 */

use Drupal\Core\Entity\EntityInterface;
9
use Drupal\Core\Language\Language;
10 11
use Drupal\field\Plugin\Core\Entity\Field;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
12

13
/**
14
 * Returns a form element to configure field synchronization.
15
 *
16
 * @param \Drupal\field\Plugin\Core\Entity\Field $field
17
 *   A field definition array.
18
 * @param \Drupal\field\Plugin\Core\Entity\FieldInstance $instance
19 20 21 22 23
 *   A field instance definition object.
 *
 * @return array
 *   A form element to configure field synchronization.
 */
24
function translation_entity_field_sync_widget(Field $field, FieldInstance $instance) {
25 26 27 28 29 30 31 32 33 34 35
  $element = array();

  if (!empty($field['settings']['column_groups']) && count($field['settings']['column_groups']) > 1) {
    $options = array();
    $default = array();

    foreach ($field['settings']['column_groups'] as $group => $info) {
      $options[$group] = $info['label'];
      $default[$group] = !empty($info['translatable']) ? $group : FALSE;
    }

36 37
    $settings = array('dependent_selectors' => array('instance[settings][translation_sync]' => array('file')));

38 39 40 41 42
    $element = array(
      '#type' => 'checkboxes',
      '#title' => t('Translatable elements'),
      '#options' => $options,
      '#default_value' => !empty($instance['settings']['translation_sync']) ? $instance['settings']['translation_sync'] : $default,
43
      '#attached' => array(
44 45 46
        'library' => array(
          array('translation_entity', 'drupal.translation_entity.admin'),
        ),
47 48 49 50
        'js' => array(
          array('data' => array('translationEntityDependentOptions' => $settings), 'type' => 'setting'),
        ),
      ),
51 52 53 54 55 56 57 58
    );
  }

  return $element;
}

/**
 * (proxied) Implements hook_form_FORM_ID_alter().
59 60 61 62 63 64 65 66 67 68 69 70 71 72
 */
function _translation_entity_form_language_content_settings_form_alter(array &$form, array &$form_state) {
  // Inject into the content language settings the translation settings if the
  // user has the required permission.
  if (!user_access('administer entity translation')) {
    return;
  }

  $default = $form['entity_types']['#default_value'];
  foreach ($default as $entity_type => $enabled) {
    $default[$entity_type] = $enabled || translation_entity_enabled($entity_type) ? $entity_type : FALSE;
  }
  $form['entity_types']['#default_value'] = $default;

73
  $form['#attached']['library'][] = array('translation_entity', 'drupal.translation_entity.admin');
74
  $form['#attached']['js'][] = array('data' => drupal_get_path('module', 'translation_entity') . '/translation_entity.admin.js', 'type' => 'file');
75

76
  $dependent_options_settings = array();
77
  foreach ($form['#labels'] as $entity_type => $label) {
78
    $entity_info = entity_get_info($entity_type);
79
    foreach (entity_get_bundles($entity_type) as $bundle => $bundle_info) {
80 81 82 83 84
      // Here we do not want the widget to be altered and hold also the "Enable
      // translation" checkbox, which would be redundant. Hence we add this key
      // to be able to skip alterations.
      $form['settings'][$entity_type][$bundle]['settings']['language']['#translation_entity_skip_alter'] = TRUE;

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
      // Only show the checkbox to enable translation if the bundles in the
      // entity might have fields and if there are fields to translate.
      if (!empty($entity_info['fieldable'])) {
        $fields = field_info_instances($entity_type, $bundle);
        if ($fields) {
          $form['settings'][$entity_type][$bundle]['translatable'] = array(
            '#type' => 'checkbox',
            '#default_value' => translation_entity_enabled($entity_type, $bundle),
          );

          // @todo Exploit field definitions once all core entities and field
          // types are migrated to the Entity Field API.
          foreach ($fields as $field_name => $instance) {
            $field = field_info_field($field_name);
            $form['settings'][$entity_type][$bundle]['fields'][$field_name] = array(
              '#label' => $instance['label'],
              '#type' => 'checkbox',
              '#default_value' => $field['translatable'],
            );
            $column_element = translation_entity_field_sync_widget($field, $instance);
            if ($column_element) {
              $form['settings'][$entity_type][$bundle]['columns'][$field_name] = $column_element;
107

108 109 110 111
              if (isset($column_element['#options']['file'])) {
                $dependent_options_settings["settings[{$entity_type}][{$bundle}][columns][{$field_name}]"] = array('file');
              }
            }
112
          }
113
        }
114 115 116
      }
    }
  }
117 118
  $settings = array('dependent_selectors' => $dependent_options_settings);
  $form['#attached']['js'][] = array('data' => array('translationEntityDependentOptions' => $settings), 'type' => 'setting');
119 120 121 122
  $form['#validate'][] = 'translation_entity_form_language_content_settings_validate';
  $form['#submit'][] = 'translation_entity_form_language_content_settings_submit';
}

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
/**
 * (proxied) Implements hook_preprocess_HOOK();
 */
function _translation_entity_preprocess_language_content_settings_table(&$variables) {
  // Alter the 'build' variable injecting the translation settings if the user
  // has the required permission.
  if (!user_access('administer entity translation')) {
    return;
  }

  $element = $variables['element'];
  $build = &$variables['build'];

  array_unshift($build['#header'], array('data' => t('Translatable'), 'class' => array('translatable')));
  $rows = array();

  foreach (element_children($element) as $bundle) {
    $field_names = !empty($element[$bundle]['fields']) ? element_children($element[$bundle]['fields']) : array();
141 142 143
    if (!empty($element[$bundle]['translatable'])) {
      $checkbox_id = $element[$bundle]['translatable']['#id'];
    }
144 145
    $rows[$bundle] = $build['#rows'][$bundle];

146 147 148 149 150 151
    if (!empty($element[$bundle]['translatable'])) {
      $translatable = array(
        'data' => $element[$bundle]['translatable'],
        'class' => array('translatable'),
      );
      array_unshift($rows[$bundle]['data'], $translatable);
152

153 154 155 156 157 158 159 160
      $rows[$bundle]['data'][1]['data']['#prefix'] = '<label for="' . $checkbox_id . '">';
    }
    else {
      $translatable = array(
        'class' => array('untranslatable'),
      );
      array_unshift($rows[$bundle]['data'], $translatable);
    }
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238

    foreach ($field_names as $field_name) {
      $field_element = &$element[$bundle]['fields'][$field_name];
      $rows[] = array(
        'data' => array(
          array(
            'data' => drupal_render($field_element),
            'class' => array('translatable'),
          ),
          array(
            'data' => array(
              '#prefix' => '<label for="' . $field_element['#id'] . '">',
              '#suffix' => '</label>',
              'bundle' => array(
                '#prefix' => '<span class="element-invisible">',
                '#suffix' => '</span> ',
                '#markup' => check_plain($element[$bundle]['settings']['#label']),
              ),
              'field' => array(
                '#markup' => check_plain($field_element['#label']),
              ),
            ),
            'class' => array('field'),
          ),
          array(
            'data' => '',
            'class' => array('operations'),
          ),
        ),
        'class' => array('field-settings'),
      );

      if (!empty($element[$bundle]['columns'][$field_name])) {
        $column_element = &$element[$bundle]['columns'][$field_name];
        foreach (element_children($column_element) as $key) {
          $column_label = $column_element[$key]['#title'];
          unset($column_element[$key]['#title']);
          $rows[] = array(
            'data' => array(
              array(
                'data' => drupal_render($column_element[$key]),
                'class' => array('translatable'),
              ),
              array(
                'data' => array(
                  '#prefix' => '<label for="' . $column_element[$key]['#id'] . '">',
                  '#suffix' => '</label>',
                  'bundle' => array(
                    '#prefix' => '<span class="element-invisible">',
                    '#suffix' => '</span> ',
                    '#markup' => check_plain($element[$bundle]['settings']['#label']),
                  ),
                  'field' => array(
                    '#prefix' => '<span class="element-invisible">',
                    '#suffix' => '</span> ',
                    '#markup' => check_plain($field_element['#label']),
                  ),
                  'columns' => array(
                    '#markup' => check_plain($column_label),
                  ),
                ),
                'class' => array('column'),
              ),
              array(
                'data' => '',
                'class' => array('operations'),
              ),
            ),
            'class' => array('column-settings'),
          );
        }
      }
    }
  }

  $build['#rows'] = $rows;
}

239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
/**
 * Form validation handler for translation_entity_admin_settings_form().
 *
 * @see translation_entity_admin_settings_form_submit()
 */
function translation_entity_form_language_content_settings_validate(array $form, array &$form_state) {
  $settings = &$form_state['values']['settings'];
  foreach ($settings as $entity_type => $entity_settings) {
    foreach ($entity_settings as $bundle => $bundle_settings) {
      if (!empty($bundle_settings['translatable'])) {
        $name = "settings][$entity_type][$bundle][translatable";

        $translatable_fields = isset($settings[$entity_type][$bundle]['fields']) ? array_filter($settings[$entity_type][$bundle]['fields']) : FALSE;
        if (empty($translatable_fields)) {
          $t_args = array('%bundle' => $form['settings'][$entity_type][$bundle]['settings']['#label']);
          form_set_error($name, t('At least one field needs to be translatable to enable %bundle for translation.', $t_args));
        }

        $values = $bundle_settings['settings']['language'];
258
        if (language_is_locked($values['langcode']) && empty($values['language_show'])) {
259
          foreach (language_list(Language::STATE_LOCKED) as $language) {
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
            $locked_languages[] = $language->name;
          }
          form_set_error($name, t('Translation is not supported if language is always one of: @locked_languages', array('@locked_languages' => implode(', ', $locked_languages))));
        }
      }
    }
  }
}

/**
 * Form submission handler for translation_entity_admin_settings_form().
 *
 * @see translation_entity_admin_settings_form_validate()
 */
function translation_entity_form_language_content_settings_submit(array $form, array &$form_state) {
  $entity_types = $form_state['values']['entity_types'];
  $settings = &$form_state['values']['settings'];

  // If an entity type is not translatable all its bundles and fields must be
  // marked as non-translatable. Similarly, if a bundle is made non-translatable
  // all of its fields will be not translatable.
  foreach ($settings as $entity_type => &$entity_settings) {
    foreach ($entity_settings as $bundle => &$bundle_settings) {
283 284 285
      if (!empty($bundle_settings['translatable'])) {
        $bundle_settings['translatable'] = $bundle_settings['translatable'] && $entity_types[$entity_type];
      }
286 287 288
      if (!empty($bundle_settings['fields'])) {
        foreach ($bundle_settings['fields'] as $field_name => $translatable) {
          $bundle_settings['fields'][$field_name] = $translatable && $bundle_settings['translatable'];
289 290 291 292 293
          // If we have column settings and no column is translatable, no point
          // in making the field translatable.
          if (isset($bundle_settings['columns'][$field_name]) && !array_filter($bundle_settings['columns'][$field_name])) {
            $bundle_settings['fields'][$field_name] = FALSE;
          }
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
        }
      }
    }
  }

  _translation_entity_update_field_translatability($settings);
  drupal_set_message(t('Settings successfully updated.'));
}

/**
 * Stores entity translation settings.
 *
 * @param array $settings
 *   An associative array of settings keyed by entity type and bundle. At bundle
 *   level the following keys are available:
 *   - translatable: The bundle translatability status, which is a bool.
 *   - settings: An array of language configuration settings as defined by
 *     language_save_default_configuration().
 *   - fields: An associative array with field names as keys and a boolean as
 *     value, indicating field translatability.
 *
 * @todo Remove this migration entirely once the Field API is converted to the
 *   Entity Field API.
 */
function _translation_entity_update_field_translatability($settings) {
  $fields = array();
  foreach ($settings as $entity_type => $entity_settings) {
    foreach ($entity_settings as $bundle => $bundle_settings) {
      // Collapse field settings since here we have per instance settings, but
      // translatability has per-field scope. We assume that all the field
      // instances have the same value.
      if (!empty($bundle_settings['fields'])) {
        foreach ($bundle_settings['fields'] as $field_name => $translatable) {
          // If a field is enabled for translation for at least one instance we
          // need to mark it as translatable.
          $fields[$field_name] = $translatable || !empty($fields[$field_name]);
        }
      }
      // @todo Store non-configurable field settings to be able to alter their
      //   definition afterwards.
    }
  }

  $operations = array();
  foreach ($fields as $field_name => $translatable) {
    $field = field_info_field($field_name);
    if ($field['translatable'] != $translatable) {
      // If a field is untranslatable, it can have no data except under
342
      // Language::LANGCODE_NOT_SPECIFIED. Thus we need a field to be translatable before
343
      // we convert data to the entity language. Conversely we need to switch
344
      // data back to Language::LANGCODE_NOT_SPECIFIED before making a field
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
      // untranslatable lest we lose information.
      $field_operations = array(
        array('translation_entity_translatable_switch', array($translatable, $field_name)),
      );
      if (field_has_data($field)) {
        $field_operations[] = array('translation_entity_translatable_batch', array($translatable, $field_name));
        $field_operations = $translatable ? $field_operations : array_reverse($field_operations);
      }
      $operations = array_merge($operations, $field_operations);
    }
  }

  // As last operation store the submitted settings.
  $operations[] = array('translation_entity_save_settings', array($settings));

  $batch = array(
    'title' => t('Updating translatability for the selected fields'),
    'operations' => $operations,
    'finished' => 'translation_entity_translatable_batch_done',
    'file' => drupal_get_path('module', 'translation_entity') . '/translation_entity.admin.inc',
  );
  batch_set($batch);
}

369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
/**
 * Form constructor for the confirmation of translatability switching.
 */
function translation_entity_translatable_form(array $form, array &$form_state, $field_name) {
  $field = field_info_field($field_name);
  $t_args = array('%name' => $field_name);

  $warning = t('By submitting this form these changes will apply to the %name field everywhere it is used.', $t_args);
  if ($field['translatable']) {
    $title = t('Are you sure you want to disable translation for the %name field?', $t_args);
    $warning .= "<br>" . t("<strong>All the existing translations of this field will be deleted.</strong><br>This action cannot be undone.");
  }
  else {
    $title = t('Are you sure you want to enable translation for the %name field?', $t_args);
  }

  // We need to keep some information for later processing.
  $form_state['field'] = $field;

  // Store the 'translatable' status on the client side to prevent outdated form
  // submits from toggling translatability.
  $form['translatable'] = array(
    '#type' => 'hidden',
    '#default_value' => $field['translatable'],
  );

  return confirm_form($form, $title, '', $warning);
}

/**
 * Form submission handler for translation_entity_translatable_form().
 *
 * This submit handler maintains consistency between the translatability of an
 * entity and the language under which the field data is stored. When a field is
 * marked as translatable, all the data in
404
 * $entity->{field_name}[Language::LANGCODE_NOT_SPECIFIED] is moved to
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
 * $entity->{field_name}[$entity_language]. When a field is marked as
 * untranslatable the opposite process occurs. Note that marking a field as
 * untranslatable will cause all of its translations to be permanently removed,
 * with the exception of the one corresponding to the entity language.
 */
function translation_entity_translatable_form_submit(array $form, array $form_state) {
  // This is the current state that we want to reverse.
  $translatable = $form_state['values']['translatable'];
  $field_name = $form_state['field']['field_name'];
  $field = field_info_field($field_name);

  if ($field['translatable'] !== $translatable) {
    // Field translatability has changed since form creation, abort.
    $t_args = array('%field_name');
    $msg = $translatable ?
      t('The field %field_name is already translatable. No change was performed.', $t_args):
      t('The field %field_name is already untranslatable. No change was performed.', $t_args);
    drupal_set_message($msg, 'warning');
    return;
  }

  // If a field is untranslatable, it can have no data except under
427
  // Language::LANGCODE_NOT_SPECIFIED. Thus we need a field to be translatable before we
428
  // convert data to the entity language. Conversely we need to switch data back
429
  // to Language::LANGCODE_NOT_SPECIFIED before making a field untranslatable lest we lose
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
  // information.
  $operations = array(
    array('translation_entity_translatable_batch', array(!$translatable, $field_name)),
    array('translation_entity_translatable_switch', array(!$translatable, $field_name)),
  );
  $operations = $translatable ? $operations : array_reverse($operations);

  $t_args = array('%field' => $field_name);
  $title = !$translatable ? t('Enabling translation for the %field field', $t_args) : t('Disabling translation for the %field field', $t_args);

  $batch = array(
    'title' => $title,
    'operations' => $operations,
    'finished' => 'translation_entity_translatable_batch_done',
    'file' => drupal_get_path('module', 'translation_entity') . '/translation_entity.admin.inc',
  );

  batch_set($batch);
}

/**
 * Toggles translatability of the given field.
 *
 * This is called from a batch operation, but should only run once per field.
 *
 * @param bool $translatable
 *   Indicator of whether the field should be made translatable (TRUE) or
 *   untranslatble (FALSE).
 * @param string $field_name
 *   Field machine name.
 */
function translation_entity_translatable_switch($translatable, $field_name) {
  $field = field_info_field($field_name);
463 464 465
  if ($field['translatable'] !== $translatable) {
    $field['translatable'] = $translatable;
    field_update_field($field);
466 467 468 469
  }
}

/**
470
 * Batch callback: Converts field data to or from Language::LANGCODE_NOT_SPECIFIED.
471 472 473 474 475 476 477 478
 *
 * @param bool $translatable
 *   Indicator of whether the field should be made translatable (TRUE) or
 *   untranslatble (FALSE).
 * @param string $field_name
 *   Field machine name.
 */
function translation_entity_translatable_batch($translatable, $field_name, &$context) {
479 480 481
  $field = field_info_field($field_name);
  $column = isset($field['columns']['value']) ? 'value' : key($field['columns']);
  $query_field = "$field_name.$column";
482 483

  // Determine the entity types to act on.
484
  $entity_types = array();
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
  foreach (field_info_instances() as $entity_type => $info) {
    foreach ($info as $bundle => $instances) {
      foreach ($instances as $instance_field_name => $instance) {
        if ($instance_field_name == $field_name) {
          $entity_types[] = $entity_type;
          break 2;
        }
      }
    }
  }

  if (empty($context['sandbox'])) {
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = 0;

    foreach ($entity_types as $entity_type) {
      // How many entities will need processing?
502
      $query = Drupal::entityQuery($entity_type);
503
      $count = $query
504
        ->exists($query_field)
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
        ->count()
        ->execute();

      $context['sandbox']['max'] += $count;
      $context['sandbox']['progress_entity_type'][$entity_type] = 0;
      $context['sandbox']['max_entity_type'][$entity_type] = $count;
    }

    if ($context['sandbox']['max'] === 0) {
      // Nothing to do.
      $context['finished'] = 1;
      return;
    }
  }

  foreach ($entity_types as $entity_type) {
    if ($context['sandbox']['max_entity_type'][$entity_type] === 0) {
      continue;
    }

    $info = entity_get_info($entity_type);
    $offset = $context['sandbox']['progress_entity_type'][$entity_type];
527
    $query = Drupal::entityQuery($entity_type);
528
    $result = $query
529
      ->exists($query_field)
530 531 532 533 534 535 536 537 538 539 540
      ->sort($info['entity_keys']['id'])
      ->range($offset, 10)
      ->execute();

    foreach (entity_load_multiple($entity_type, $result) as $id => $entity) {
      $context['sandbox']['max_entity_type'][$entity_type] -= count($result);
      $context['sandbox']['progress_entity_type'][$entity_type]++;
      $context['sandbox']['progress']++;
      $langcode = $entity->language()->langcode;

      // Skip process for language neutral entities.
541
      if ($langcode == Language::LANGCODE_NOT_SPECIFIED) {
542 543 544 545 546 547 548 549 550
        continue;
      }

      // We need a two-step approach while updating field translations: given
      // that field-specific update functions might rely on the stored values to
      // perform their processing, see for instance file_field_update(), first
      // we need to store the new translations and only after we can remove the
      // old ones. Otherwise we might have data loss, since the removal of the
      // old translations might occur before the new ones are stored.
551
      if ($translatable && isset($entity->{$field_name}[Language::LANGCODE_NOT_SPECIFIED])) {
552
        // If the field is being switched to translatable and has data for
553
        // Language::LANGCODE_NOT_SPECIFIED then we need to move the data to the right
554
        // language.
555
        $entity->{$field_name}[$langcode] = $entity->{$field_name}[Language::LANGCODE_NOT_SPECIFIED];
556 557
        // Store the original value.
        _translation_entity_update_field($entity_type, $entity, $field_name);
558
        $entity->{$field_name}[Language::LANGCODE_NOT_SPECIFIED] = array();
559 560 561 562 563
        // Remove the language neutral value.
        _translation_entity_update_field($entity_type, $entity, $field_name);
      }
      elseif (!$translatable && isset($entity->{$field_name}[$langcode])) {
        // The field has been marked untranslatable and has data in the entity
564
        // language: we need to move it to Language::LANGCODE_NOT_SPECIFIED and drop the
565
        // other translations.
566
        $entity->{$field_name}[Language::LANGCODE_NOT_SPECIFIED] = $entity->{$field_name}[$langcode];
567 568 569 570
        // Store the original value.
        _translation_entity_update_field($entity_type, $entity, $field_name);
        // Remove translations.
        foreach ($entity->{$field_name} as $langcode => $items) {
571
          if ($langcode != Language::LANGCODE_NOT_SPECIFIED) {
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
            $entity->{$field_name}[$langcode] = array();
          }
        }
        _translation_entity_update_field($entity_type, $entity, $field_name);
      }
      else {
        // No need to save unchanged entities.
        continue;
      }
    }
  }

  $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}

/**
 * Stores the given field translations.
 */
function _translation_entity_update_field($entity_type, EntityInterface $entity, $field_name) {
  $empty = 0;
  $field = field_info_field($field_name);

  // Ensure that we are trying to store only valid data.
  foreach ($entity->{$field_name} as $langcode => $items) {
    $entity->{$field_name}[$langcode] = _field_filter_items($field, $entity->{$field_name}[$langcode]);
    $empty += empty($entity->{$field_name}[$langcode]);
  }

  // Save the field value only if there is at least one item available,
  // otherwise any stored empty field value would be deleted. If this happens
  // the range queries would be messed up.
  if ($empty < count($entity->{$field_name})) {
604 605
    field_attach_presave($entity);
    field_attach_update($entity);
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
  }
}

/**
 * Batch finished callback: Checks the exit status of the batch operation.
 */
function translation_entity_translatable_batch_done($success, $results, $operations) {
  if ($success) {
    drupal_set_message(t("Successfully changed field translation setting."));
  }
  else {
    // @todo: Do something about this case.
    drupal_set_message(t("Something went wrong while processing data. Some nodes may appear to have lost fields."), 'error');
  }
}