You are here

function drush_gathercontent_list_status in GatherContent 8.4

Same name and namespace in other branches
  1. 8.5 gathercontent.drush.inc \drush_gathercontent_list_status()
  2. 8.3 gathercontent.drush.inc \drush_gathercontent_list_status()
  3. 7.3 gathercontent.drush.inc \drush_gathercontent_list_status()

Implements drush_COMMAND().

File

./gathercontent.drush.inc, line 131
Drush command to cli config import.

Code

function drush_gathercontent_list_status($project_id = NULL) {

  /** @var \Drupal\gathercontent\DrupalGatherContentClient $client */
  $client = \Drupal::service('gathercontent.client');
  if ($project_id === NULL) {
    $account_id = DrupalGatherContentClient::getAccountId();
    if (!$account_id) {
      return drush_set_error('gathercontent_no_accounts_configured', t('No accounts configured.'));
    }
    $projects = $client
      ->projectsGet($account_id);
    $options = [];
    foreach ($projects as $id => $project) {
      $options[$id] = $id . ' | ' . $project->name;
    }
    $project_id = drush_choice($options, dt('Select a project ID: '));
  }
  if (!$project_id) {
    return drush_set_error('gathercontent_unknown_mapping_id', dt('Unknown mapping ID.'));
  }
  $statuses = $client
    ->projectStatusesGet($project_id);
  $mappings = [];
  foreach ($statuses as $status) {
    $mappings[$status->id] = [
      'status_id' => $status->id,
      'status_label' => $status->name,
    ];
  }
  return $mappings;
}