Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Title: Add a Derivative in the Core namespace with t() as a helper method » Add a DerivativeBase in the Core namespace with t() as a helper method
Issue tags: +Plugin system
tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
Status: Active » Needs review
FileSize
28.37 KB

Copied the methods straight from PluginBase, and updated all derivatives.

Status: Needs review » Needs work

The last submitted patch, derivative-2112575-2.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
1021 bytes
29.22 KB

Drupal\rest\Plugin\Derivative\EntityDerivative had an extraneous layer of static caching that broke when combined with the base class

Interdiff made with -w

neclimdul’s picture

  1. +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php
    @@ -63,19 +57,6 @@ public static function create(ContainerInterface $container, $base_plugin_id) {
    -  public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) {
    -    if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
    -      return $this->derivatives[$derivative_id];
    -    }
    -    $this->getDerivativeDefinitions($base_plugin_definition);
    -    if (isset($this->derivatives[$derivative_id])) {
    -      return $this->derivatives[$derivative_id];
    -    }
    -  }
    -
    -  /**
    -   * {@inheritdoc}
    -   */
    

    Asked tim about these. These classes implemented the interface and didn't extend the Component base class so had copied the implementation. Use the base class implementation now.

  2. +++ b/core/lib/Drupal/Core/Plugin/Discovery/ContainerDerivativeInterface.php
    @@ -20,10 +20,10 @@
    -   * @param string $plugin_id
    +   * @param string $base_plugin_id
        *   The base plugin ID for the plugin ID.
        *
    -   * @return static
    +   * @return self
        *   Returns an instance of this fetcher.
    

    +1

  3. +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/TestDerivativeDiscovery.php
    @@ -8,19 +8,12 @@
    -class TestDerivativeDiscovery implements DerivativeInterface {
    -
    -  /**
    -   * {@inheritdoc}
    -   */
    -  public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) {
    -    $definitions = $this->getDerivativeDefinitions($base_plugin_definition);
    -    return $definitions[$derivative_id];
    -  }
    

    This one is a little different. I don't know if bypassing the local cache is on purpose or not.

Overall, big +1!

dawehner’s picture

Status: Needs review » Needs work
+++ b/core/modules/content_translation/lib/Drupal/content_translation/Plugin/Derivative/ContentTranslationLocalTasks.php
@@ -77,11 +77,11 @@ public function getDerivativeDefinitions(array $base_plugin_definition) {
+          $this->derivatives[$entity_tab]['title'] = $this->t('Edit');
...
+          $this->derivatives[$translation_tab]['title'] = $this->t('Translate');

These titles will be translated again later, so let's remove them here.

Xano’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

This is no longer needed now we have StringTranslationTrait.