You are here

public function AdjustmentTypeManager::processDefinition in Commerce Core 8.2

Performs extra processing on plugin definitions.

By default we add defaults for the type to the definition. If a type has additional processing logic they can do that by replacing or extending the method.

Overrides DefaultPluginManager::processDefinition

File

modules/order/src/AdjustmentTypeManager.php, line 68

Class

AdjustmentTypeManager
Manages discovery and instantiation of commerce_adjustment_type plugins.

Namespace

Drupal\commerce_order

Code

public function processDefinition(&$definition, $plugin_id) {
  parent::processDefinition($definition, $plugin_id);
  $definition['id'] = $plugin_id;
  foreach ([
    'label',
  ] as $required_property) {
    if (empty($definition[$required_property])) {
      throw new PluginException(sprintf('The adjustment type %s must define the %s property.', $plugin_id, $required_property));
    }
  }

  // Provide fallback labels for contrib adjustment types defined before 2.4.
  if (empty($definition['singular_label'])) {
    $label = mb_strtolower($definition['label']);
    $definition['singular_label'] = $this
      ->t('@label adjustment', [
      '@label' => $label,
    ]);
  }
  if (empty($definition['plural_label'])) {
    $label = mb_strtolower($definition['label']);
    $definition['plural_label'] = $this
      ->t('@label adjustments', [
      '@label' => $label,
    ]);
  }
}