You are here

protected function SalesforceMappingCommandsBase::getMappingsFromName in Salesforce Suite 8.3

Same name and namespace in other branches
  1. 8.4 modules/salesforce_mapping/src/Commands/SalesforceMappingCommandsBase.php \Drupal\salesforce_mapping\Commands\SalesforceMappingCommandsBase::getMappingsFromName()
  2. 5.0.x modules/salesforce_mapping/src/Commands/SalesforceMappingCommandsBase.php \Drupal\salesforce_mapping\Commands\SalesforceMappingCommandsBase::getMappingsFromName()

Given a mapping name (and optional direction), get an array of mappings.

Parameters

string $name: 'ALL' to load all mappings, or a mapping id.

string $dir: 'push'|'pull'|NULL to load limit mappings by push or pull types.

Return value

\Drupal\salesforce_mapping\Entity\SalesforceMappingInterface[] The mappings.

2 calls to SalesforceMappingCommandsBase::getMappingsFromName()
SalesforceMappingCommandsBase::getPullMappingsFromName in modules/salesforce_mapping/src/Commands/SalesforceMappingCommandsBase.php
Given a mappin gname, get an array of matching pull mappings.
SalesforceMappingCommandsBase::getPushMappingsFromName in modules/salesforce_mapping/src/Commands/SalesforceMappingCommandsBase.php
Given a mapping name, get an array of matching push mappings.

File

modules/salesforce_mapping/src/Commands/SalesforceMappingCommandsBase.php, line 128

Class

SalesforceMappingCommandsBase
Shared command base for Salesforce Drush commands.

Namespace

Drupal\salesforce_mapping\Commands

Code

protected function getMappingsFromName($name, $dir = NULL) {
  $mappings = [];
  if ($name == 'ALL') {
    if ($dir == 'pull') {
      $mappings = $this->mappingStorage
        ->loadPullMappings();
    }
    elseif ($dir == 'push') {
      $mappings = $this->mappingStorage
        ->loadPushMappings();
    }
    else {
      $mappings = $this->mappingStorage
        ->loadMultiple();
    }
  }
  else {
    $mapping = $this->mappingStorage
      ->load($name);
    if ($dir == 'push' && !$mapping
      ->doesPush()) {
      throw new \Exception(dt("Mapping !name does not push.", [
        '!name' => $name,
      ]));
    }
    elseif ($dir == 'pull' && !$mapping
      ->doesPull()) {
      throw new \Exception(dt("Mapping !name does not pull.", [
        '!name' => $name,
      ]));
    }
    $mappings = [
      $mapping,
    ];
  }
  $mappings = array_filter($mappings);
  if (empty($mappings)) {
    if ($dir == 'push') {
      throw new \Exception(dt('No push mappings loaded'));
    }
    if ($dir == 'pull') {
      throw new \Exception(dt('No pull mappings loaded'));
    }
  }
  return $mappings;
}