addTranslatableProperty example

$definition['id'] = $plugin_id;
  }

  /** * 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;
  }

  /** * Gets the plugin factory. * * @return \Drupal\Component\Plugin\Factory\FactoryInterface */
  
$this->account = $account;
    $this->alterInfo('menu_local_actions');
    $this->setCacheBackend($cache_backend, 'local_action_plugins:' . $language_manager->getCurrentLanguage()->getId()['local_action']);
  }

  /** * {@inheritdoc} */
  protected function getDiscovery() {
    if (!isset($this->discovery)) {
      $yaml_discovery = new YamlDiscovery('links.action', $this->moduleHandler->getModuleDirectories());
      $yaml_discovery->addTranslatableProperty('title', 'title_context');
      $this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery);
    }
    return $this->discovery;
  }

  /** * {@inheritdoc} */
  public function getTitle(LocalActionInterface $local_action) {
    $controller = [$local_action, 'getTitle'];
    $arguments = $this->argumentResolver->getArguments($this->requestStack->getCurrentRequest()$controller);
    
$this->requestStack = $request_stack;
    $this->alterInfo('contextual_links_plugins');
    $this->setCacheBackend($cache_backend, 'contextual_links_plugins:' . $language_manager->getCurrentLanguage()->getId()['contextual_links_plugins']);
  }

  /** * {@inheritdoc} */
  protected function getDiscovery() {
    if (!isset($this->discovery)) {
      $yaml_discovery = new YamlDiscovery('links.contextual', $this->moduleHandler->getModuleDirectories());
      $yaml_discovery->addTranslatableProperty('title', 'title_context');
      $this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery);
    }
    return $this->discovery;
  }

  /** * {@inheritdoc} */
  public function processDefinition(&$definition$plugin_id) {
    parent::processDefinition($definition$plugin_id);

    
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(TranslatableMarkup::class$plugin_1['title']);
    $this->assertEquals([]$plugin_1['title']->getOptions());
    $this->assertInstanceOf(TranslatableMarkup::class$plugin_2['title']);
    $this->assertEquals(['context' => 'test-context']$plugin_2['title']->getOptions());
  }

  
return $this->moduleHandler->moduleExists($provider) || $this->themeHandler->themeExists($provider);
  }

  /** * {@inheritdoc} */
  protected function getDiscovery() {
    if (!$this->discovery) {
      $discovery = new AnnotatedClassDiscovery($this->subdir, $this->namespaces, $this->pluginDefinitionAnnotationName, $this->additionalAnnotationNamespaces);
      $discovery = new YamlDiscoveryDecorator($discovery, 'layouts', $this->moduleHandler->getModuleDirectories() + $this->themeHandler->getThemeDirectories());
      $discovery
        ->addTranslatableProperty('label')
        ->addTranslatableProperty('description')
        ->addTranslatableProperty('category');
      $discovery = new AnnotationBridgeDecorator($discovery$this->pluginDefinitionAnnotationName);
      $discovery = new ContainerDerivativeDiscoveryDecorator($discovery);
      $this->discovery = $discovery;
    }
    return $this->discovery;
  }

  /** * {@inheritdoc} */
'subdir1' => [
          'plugin1.yml' => "id: plugin1\ntest_provider: module_a\ntitle: 'test title'",
          'plugin2.yml' => "id: plugin2\ntest_provider: module_a\ntitle: 'test title'\ntitle_context: test-context",
        ],
      ],
    ]);
    $directories = [
      'module_a' => vfsStream::url('modules/module_a/subdir1'),
    ];

    $discovery = new YamlDirectoryDiscovery($directories, 'test');
    $discovery->addTranslatableProperty('title', 'title_context');
    $definitions = $discovery->getDefinitions();

    $this->assertCount(2, $definitions);
    $plugin_1 = $definitions['plugin1'];
    $plugin_2 = $definitions['plugin2'];

    $this->assertInstanceOf(TranslatableMarkup::class$plugin_1['title']);
    $this->assertEquals([]$plugin_1['title']->getOptions());
    $this->assertInstanceOf(TranslatableMarkup::class$plugin_2['title']);
    $this->assertEquals(['context' => 'test-context']$plugin_2['title']->getOptions());
  }

}
$this->moduleHandler = $module_handler;
    $this->alterInfo('local_tasks');
    $this->setCacheBackend($cache, 'local_task_plugins:' . $language_manager->getCurrentLanguage()->getId()['local_task']);
  }

  /** * {@inheritdoc} */
  protected function getDiscovery() {
    if (!isset($this->discovery)) {
      $yaml_discovery = new YamlDiscovery('links.task', $this->moduleHandler->getModuleDirectories());
      $yaml_discovery->addTranslatableProperty('title', 'title_context');
      $this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery);
    }
    return $this->discovery;
  }

  /** * {@inheritdoc} */
  public function processDefinition(&$definition$plugin_id) {
    parent::processDefinition($definition$plugin_id);
    // If there is no route name, this is a broken definition.
Home | Imprint | This part of the site doesn't use cookies.