/** * {@inheritdoc} */ public function createInstance($plugin_id, array $configuration = []) { // Normally we must never interact with plugins' internal configuration, // but Drupal core's entity reference selection plugins require such // interaction, as they fail to provide APIs for setting required // configuration. See https://www.drupal.org/node/2636322. $default_configuration = ['target_type' => $this->targetEntityTypeId, 'handler_settings' => ['sort' => ['direction' => 'ASC', 'field' => NULL], 'target_bundles' => []]]; $configuration = NestedArray::mergeDeep($default_configuration, $configuration); return parent::createInstance($plugin_id, $configuration); }
/** * @covers ::__construct * @covers ::createInstance * * @expectedException \Drupal\Component\Plugin\Exception\PluginNotFoundException */ public function testCreateInstanceWithNonExistingPluginAndOverriddenDiscovery() { $plugin_manager = $this->getMock(PluginManagerInterface::class); $this->decoratedDiscovery = $this->getMock(DiscoveryInterface::class); $this->decoratedFactory = $plugin_manager; $this->sut = new PluginManagerDecorator($plugin_manager, $this->decoratedDiscovery); $plugin_id = $this->randomMachineName(); $this->decoratedDiscovery->expects($this->once())->method('getDefinitions')->willReturn([]); $this->decoratedFactory->expects($this->never())->method('createInstance'); $this->sut->createInstance($plugin_id); }