We previously had a bug with the _entity_id that was accidentally exported to config (as null).
As a consequence, our code present in initializePlugin() that adds the _entityId wasn't working properly in that case since we're using the + operator that will only add the _entity_id if not present already.

Comments

jsacksick created an issue. See original summary.

jsacksick’s picture

jsacksick’s picture

Status: Active » Needs review
StatusFileSize
new1.45 KB
bojanz’s picture

Title: Fix our PluginCollection classes » $this->entityId empty in plugins after a bad export

  • bojanz committed 13437e0 on 8.x-2.x authored by jsacksick
    Issue #2903178 by jsacksick: $this->entityId empty in plugins after a...
bojanz’s picture

Status: Needs review » Fixed
edaa’s picture

Status: Fixed » Needs review

It does not work on Drupal 8.4.x, I know Commerce 2.x does not support Drupal 8.4 until it's stable, maybe it's useful for someone.

Because the base class DefaultSingleLazyPluginCollection of PaymentGatewayPluginCollection and TaxTypePluginCollection is actually not lazy, the plugin in them will be initialized before their _constructor completed, the plugin's entityId is always NULL.

For example PaymentGatewayPluginCollection:

class PaymentGatewayPluginCollection extends DefaultSingleLazyPluginCollection {
  public function __construct(PluginManagerInterface $manager, $instance_id, array $configuration, $entity_id) {
    parent::__construct($manager, $instance_id, $configuration);

    // The instance (identified by $instance_id) has been initialized when reaching here.

    $this->entityId = $entity_id;
  }
}

We need to set entityId earlier:

class PaymentGatewayPluginCollection extends DefaultSingleLazyPluginCollection {
  public function __construct(PluginManagerInterface $manager, $instance_id, array $configuration, $entity_id) {
    $this->entityId = $entity_id;

    parent::__construct($manager, $instance_id, $configuration);   
  }
}
edaa’s picture

Status: Needs review » Fixed
bojanz’s picture

@edwardaa
Can you please open a separate issue for this? If Drupal 8.4 introduced a regression, we should find in which issue it happened.

edaa’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.