You are here

function _salesforce_drush_get_mapping in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 salesforce.drush.inc \_salesforce_drush_get_mapping()
  2. 8.3 salesforce.drush.inc \_salesforce_drush_get_mapping()

Get a mapping from the given name, or from user input if name is empty.

Parameters

string $name: The mapping name.

Return value

\Drupal\salesforce_mapping\Entity\SalesforceMappingInterface|null The mapping.

6 calls to _salesforce_drush_get_mapping()
drush_salesforce_pull_sf_pull_file in modules/salesforce_pull/salesforce_pull.drush.inc
Queues records for pull from Salesforce from the given file and mapping.
drush_salesforce_pull_sf_pull_query in modules/salesforce_pull/salesforce_pull.drush.inc
Queues records for pull from salesforce for the given mapping.
drush_salesforce_pull_sf_pull_set in modules/salesforce_pull/salesforce_pull.drush.inc
Set pull time on all mappings, or the given mapping by name.
drush_salesforce_push_sf_push_queue in modules/salesforce_push/salesforce_push.drush.inc
Implements drush_hook_COMMAND().
drush_salesforce_push_unmapped in modules/salesforce_push/salesforce_push.drush.inc
Implements drush_hook_COMMAND().

... See full list

File

./salesforce.drush.inc, line 462
Drush integration for Salesforce.

Code

function _salesforce_drush_get_mapping($name = NULL) {
  _drush_salesforce_deprecated();
  $mapping_storage = \Drupal::service('entity_type.manager')
    ->getStorage('salesforce_mapping');
  if (empty($name)) {
    $choices = array_keys($mapping_storage
      ->loadMultiple());
    if (empty($choices)) {
      drush_log(dt('No mappings found.'), 'error');
      return;
    }
    ksort($choices);
    $choice = drush_choice($choices, dt('Enter a number to choose which mapping to use.'));
    if ($choice === FALSE) {
      return;
    }
    $name = $choices[$choice];
  }
  $mapping = $mapping_storage
    ->load($name);
  if (empty($mapping)) {
    drush_log(dt('Mapping !name not found.', [
      '!name' => $name,
    ]), 'error');
  }
  return $mapping;
}