/** * @covers ::getDefinitions * @covers ::processDecoratedDefinitions */ public function testGetDefinitions() { $decorated_plugin_id_a = $this->randomMachineName(); $decorated_plugin_definition_a = ['id' => $decorated_plugin_id_a]; $decorated_plugin_id_b = $this->randomMachineName(); $decorated_plugin_definition_b = ['id' => $decorated_plugin_id_b]; $decorated_plugin_definitions = [$decorated_plugin_id_a => $decorated_plugin_definition_a, $decorated_plugin_id_b => $decorated_plugin_definition_b]; $this->pluginManager->expects($this->once())->method('getDefinitions')->willReturn($decorated_plugin_definitions); $typed_plugin_definition_a = $this->getMock(PluginDefinitionInterface::class); $typed_plugin_definition_b = $this->getMock(PluginDefinitionInterface::class); $map = [[$decorated_plugin_definition_a, $typed_plugin_definition_a], [$decorated_plugin_definition_b, $typed_plugin_definition_b]]; $this->pluginType->expects($this->atLeastOnce())->method('ensureTypedPluginDefinition')->willReturnMap($map); $expected_plugin_definitions = [$decorated_plugin_id_a => $typed_plugin_definition_a, $decorated_plugin_id_b => $typed_plugin_definition_b]; $this->assertSame($expected_plugin_definitions, $this->sut->getDefinitions()); }
/** * Handles the route. * * @param string $plugin_type_id * The plugin type ID. * * @return mixed[]|\Symfony\Component\HttpFoundation\Response * A render array or a Symfony response. */ public function execute($plugin_type_id) { if (!$this->pluginTypeManager->hasPluginType($plugin_type_id)) { throw new NotFoundHttpException(); } $plugin_type = $this->pluginTypeManager->getPluginType($plugin_type_id); $build = ['#empty' => $this->t('There are no available plugins.'), '#header' => [$this->t('Type'), $this->t('Description'), $this->t('Provider')], '#type' => 'table']; $plugin_discovery = new TypedDefinitionEnsuringPluginDiscoveryDecorator($plugin_type); /** @var \Drupal\plugin\PluginDefinition\PluginDefinitionInterface[] $plugin_definitions */ $plugin_definitions = []; foreach ($plugin_discovery->getDefinitions() as $plugin_definition) { $label = $plugin_definition instanceof PluginLabelDefinitionInterface ? (string) $plugin_definition->getLabel() : $plugin_definition->getId(); $plugin_definitions[$label] = $plugin_definition; } uksort($plugin_definitions, 'strnatcasecmp'); foreach ($plugin_definitions as $label => $plugin_definition) { $build[$plugin_definition->getId()] = ['label' => ['#markup' => $label], 'description' => ['#markup' => $plugin_definition instanceof PluginDescriptionDefinitionInterface ? (string) $plugin_definition->getDescription() : NULL], 'provider' => ['#markup' => $this->getProviderLabel($plugin_definition->getProvider())]]; } return $build; }