/** * @covers ::getDefinitions */ public function testGetDefinitionsWithTranslatableDefinitions() { vfsStream::setup('root'); $file_1 = <<<'EOS' test_plugin: title: test title EOS; $file_2 = <<<'EOS' test_plugin2: title: test title2 title_context: 'test-context' EOS; vfsStream::create(['test_1' => ['test_1.test.yml' => $file_1], 'test_2' => ['test_2.test.yml' => $file_2]]); $discovery = new YamlDiscovery('test', ['test_1' => vfsStream::url('root/test_1'), 'test_2' => vfsStream::url('root/test_2')]); $discovery->addTranslatableProperty('title', 'title_context'); $definitions = $discovery->getDefinitions(); $this->assertCount(2, $definitions); $plugin_1 = $definitions['test_plugin']; $plugin_2 = $definitions['test_plugin2']; $this->assertInstanceOf(TranslationWrapper::class, $plugin_1['title']); $this->assertEquals([], $plugin_1['title']->getOptions()); $this->assertInstanceOf(TranslationWrapper::class, $plugin_2['title']); $this->assertEquals(['context' => 'test-context'], $plugin_2['title']->getOptions()); }
/** * Gets the plugin discovery. * * @return \Drupal\Component\Plugin\Discovery\DiscoveryInterface */ protected function getDiscovery() { if (!isset($this->discovery)) { $yaml_discovery = new YamlDiscovery('links.menu', $this->moduleHandler->getModuleDirectories()); $yaml_discovery->addTranslatableProperty('title', 'title_context'); $yaml_discovery->addTranslatableProperty('description', 'description_context'); $this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery); } return $this->discovery; }