public static function Terms::export in Hook Update Deploy Tools 7
Exports a single term based on its tid. (Typically called from Drush).
Parameters
string $tid: The tid of the Term to export.
Return value
string The URI of the item exported, or a failure message.
Overrides ExportInterface::export
File
- src/
Terms.php, line 507  
Class
- Terms
 - Public methods for dealing with Vocabularies.
 
Namespace
HookUpdateDeployToolsCode
public static function export($tid) {
  $t = get_t();
  try {
    Check::notEmpty('tid', $tid);
    Check::isNumeric('tid', $tid);
    self::canExport();
    $msg_return = '';
    // Load the term if it exists.
    $term = taxonomy_term_load($tid);
    Check::notEmpty('term', $term);
    Check::notEmpty('term name', $term->name);
    Check::notEmpty('vocabulary_machine_name', $term->vocabulary_machine_name);
    // Get the vocabulary name.
    $vocabulary = Vocabularies::loadByMachineName($term->vocabulary_machine_name, TRUE);
    Check::notEmpty('vocabulary_name', $vocabulary->name);
    $voc_term_name = self::normalizeVocTermName($vocabulary->name, $term->name);
    $file_name = self::normalizeFileName($voc_term_name);
    $storage_path = HudtInternal::getStoragePath('term');
    $file_uri = DRUPAL_ROOT . '/' . $storage_path . $file_name;
    // Add parents. These will be unpacked at import.
    $term->parents = taxonomy_get_parents($tid);
    // Get pathauto path.
    if (!empty($term->path) && isset($term->path['pathauto']) && $term->path['pathauto'] === '0') {
      // Lookup the alias and store it.
      $alias = drupal_get_path_alias("taxonomy/term/{$tid}");
      $term->path['alias'] = $alias;
    }
    // Made it this far, it exists, so export it.
    $export_contents = drupal_var_export($term);
    // Save the file.
    $msg_return = HudtInternal::writeFile($file_uri, $export_contents);
  } catch (\Exception $e) {
    // Any errors from this command do not need to be watchdog logged.
    $e->logIt = FALSE;
    $vars = array(
      '!error' => method_exists($e, 'logMessage') ? $e
        ->logMessage() : $e
        ->getMessage(),
    );
    $msg_error = $t("Caught exception:  !error", $vars);
  }
  if (!empty($msg_error)) {
    drush_log($msg_error, 'error');
  }
  return !empty($msg_return) ? $msg_return : $msg_error;
}