You are here

function drush_select_translation in Select translation 8

Select which translation of a node should be displayed.

Parameters

int $nid: The Node ID.

File

drush/select_translation.drush.inc, line 33
Drush integration for the select_translation module.

Code

function drush_select_translation($nid) {
  if (\Drupal::moduleHandler()
    ->moduleExists('select_translation') === FALSE) {
    return drush_set_error('INVALID_MODULE', dt("Module 'select_translation' doesn't exist or is uninstalled."));
  }
  $node_id = filter_var($nid, FILTER_VALIDATE_INT, [
    'options' => [
      'min_range' => 1,
    ],
  ]);
  if (!$node_id) {
    return drush_set_error('INVALID_ARGUMENT', dt("The 'nid' argument must be an integer >= 1."));
  }
  $mode = drush_get_option('mode');
  if ($mode) {
    $node = select_translation_of_node($node_id, $mode);
  }
  else {
    $node = select_translation_of_node($node_id);
  }
  if (!$node) {
    return drush_set_error('INVALID_NODE', dt("Node with 'nid' = {$nid} not available."));
  }
  \Drupal::logger("Selected translation for node {$nid}: " . $node
    ->language()
    ->getId(), LogLevel::OK);
  return $node;
}