You are here

public function PackageTypeDeriver::getDerivativeDefinitions in Commerce Shipping 8.2

Gets the definition of all derivatives of a base plugin.

Parameters

array $base_plugin_definition: The definition array of the base plugin.

Return value

array An array of full derivative definitions keyed on derivative id.

Overrides DeriverBase::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

src/Plugin/Deriver/PackageTypeDeriver.php, line 44

Class

PackageTypeDeriver
Exposes each package type config entity as a package type plugin.

Namespace

Drupal\commerce_shipping\Plugin\Deriver

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $plugin_definitions = [];
  $package_type_entities = $this->entityTypeManager
    ->getStorage('commerce_package_type')
    ->loadMultiple();

  /** @var \Drupal\commerce_shipping\Entity\PackageTypeInterface $package_type */
  foreach ($package_type_entities as $package_type) {
    $plugin_definitions[$package_type
      ->uuid()] = [
      'id' => 'commerce_package_type:' . $package_type
        ->uuid(),
      'remote_id' => 'custom',
      'label' => $package_type
        ->label(),
      'dimensions' => $package_type
        ->getDimensions(),
      'weight' => $package_type
        ->getWeight(),
    ];
  }
  return $plugin_definitions;
}