You are here

public function StockConfigForm::__construct in Commerce Stock 8

Constructs a StockConfigForm object.

Parameters

\Drupal\Core\Config\ConfigFactoryInterface $config_factory: The factory for configuration objects.

\Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager: The entity type manager.

\Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info: The entity type bundle info service.

\Drupal\commerce_stock\StockServiceManagerInterface $stock_service_manager: The stock service manager.

\Drupal\commerce_stock\StockEventsManager $stock_events_manager: The stock events plugin manager.

Overrides ConfigFormBase::__construct

File

src/Form/StockConfigForm.php, line 54

Class

StockConfigForm
The stock configuration form.

Namespace

Drupal\commerce_stock\Form

Code

public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info, StockServiceManagerInterface $stock_service_manager, StockEventsManager $stock_events_manager) {
  parent::__construct($config_factory);
  $this->stockServiceManager = $stock_service_manager;
  $this->stockEventsManager = $stock_events_manager;

  // Prepare the list of purchasable entity types and bundles.
  $entity_types = $entity_type_manager
    ->getDefinitions();
  $purchasable_entity_types = array_filter($entity_types, function ($entity_type) {
    return $entity_type
      ->isSubclassOf('\\Drupal\\commerce\\PurchasableEntityInterface');
  });
  $purchasable_entity_types = array_map(function ($entity_type) {
    return $entity_type
      ->getLabel();
  }, $purchasable_entity_types);
  foreach ($purchasable_entity_types as $type => $label) {
    $this->purchasableEntityTypes[$type] = [
      'label' => $label,
      'bundles' => [],
    ];
    foreach ($entity_type_bundle_info
      ->getBundleInfo($type) as $bundle_id => $bundle_info) {
      $this->purchasableEntityTypes[$type]['bundles'][$bundle_id] = $bundle_info['label'];
    }
  }
}