getDerivativeDefinitions example



      $this->derivatives["permissions_$bundle_type_id"] = [
        'route_name' => "entity.$bundle_type_id.entity_permissions_form",
        'weight' => 10,
        'title' => $this->t('Manage permissions'),
        'base_route' => $base_route,
      ] + $base_plugin_definition;

    }

    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}
foreach ($base_tables as $table) {
      $views_info = $views_data->get($table);
      if (empty($views_info['table']['wizard_id'])) {
        $this->derivatives[$table] = [
          'id' => 'standard',
          'base_table' => $table,
          'title' => $views_info['table']['base']['title'],
          'class' => 'Drupal\views\Plugin\views\wizard\Standard',
        ];
      }
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}
/** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
      $route_name = $mapper->getOverviewRouteName();
      $base_route = $mapper->getBaseRouteName();
      if (!empty($base_route)) {
        $this->derivatives[$route_name] = $base_plugin_definition;
        $this->derivatives[$route_name]['config_translation_plugin_id'] = $plugin_id;
        $this->derivatives[$route_name]['class'] = '\Drupal\config_translation\Plugin\Menu\LocalTask\ConfigTranslationLocalTask';
        $this->derivatives[$route_name]['route_name'] = $route_name;
        $this->derivatives[$route_name]['base_route'] = $base_route;
      }
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}
foreach ($configurable_types as $type) {
        $this->derivatives[$type] = $base_plugin_definition;
        $this->derivatives[$type]['admin_label'] = $this->t('Language switcher (@type)', ['@type' => $info[$type]['name']]);
      }
      // If there is just one configurable type then change the title of the       // block.       if (count($configurable_types) == 1) {
        $this->derivatives[reset($configurable_types)]['admin_label'] = $this->t('Language switcher');
      }
    }

    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}
/** * {@inheritdoc} * @param string $derivative_id * The ID for the derivative. * @param array $base_plugin_definition * An associative array defining the base plugin. * * @return array */
  public function getDerivativeDefinition($derivative_id$base_plugin_definition) {
    $definitions = $this->getDerivativeDefinitions($base_plugin_definition);
    return $definitions[$derivative_id];
  }

  /** * {@inheritdoc} * @param array $base_plugin_definition * An associative array defining the base plugin. * * @return array */
  public function getDerivativeDefinitions($base_plugin_definition) {
    
$container->get('views.views_data')
    );
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinition($derivative_id$base_plugin_definition) {
    if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
      return $this->derivatives[$derivative_id];
    }
    $this->getDerivativeDefinitions($base_plugin_definition);
    return $this->derivatives[$derivative_id];
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      // Just add support for entity types which have a views integration.       if (($base_table = $entity_type->getBaseTable()) && $this->viewsData->get($base_table) && $this->entityTypeManager->hasHandler($entity_type_id, 'view_builder')) {
        $this->derivatives[$entity_type_id] = [
          
$container->get('entity_type.manager')->getDefinitions()
    );
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinition($derivative_id$base_plugin_definition) {
    if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
      return $this->derivatives[$derivative_id];
    }
    $this->getDerivativeDefinitions($base_plugin_definition);
    return $this->derivatives[$derivative_id];
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    foreach ($this->entityDefinitions as $entity_type => $entity_info) {
      $class = is_subclass_of($entity_info->getClass(), 'Drupal\Core\Config\Entity\ConfigEntityInterface') ?
        'Drupal\migrate\Plugin\migrate\destination\EntityConfigBase' :
        'Drupal\migrate\Plugin\migrate\destination\EntityContentBase';
      
$this->basePluginId = $base_plugin_id;
    $this->viewStorage = $view_storage;
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinition($derivative_id$base_plugin_definition) {
    if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
      return $this->derivatives[$derivative_id];
    }
    $this->getDerivativeDefinitions($base_plugin_definition);
    return $this->derivatives[$derivative_id];
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    // Check all Views for block displays.     foreach ($this->viewStorage->loadMultiple() as $view) {
      // Do not return results for disabled views.       if (!$view->status()) {
        
/** * Adds derivatives to a list of plugin definitions. * * This should be called by the class extending this in * DiscoveryInterface::getDefinitions(). */
  protected function getDerivatives(array $base_plugin_definitions) {
    $plugin_definitions = [];
    foreach ($base_plugin_definitions as $base_plugin_id => $plugin_definition) {
      $deriver = $this->getDeriver($base_plugin_id$plugin_definition);
      if ($deriver) {
        $derivative_definitions = $deriver->getDerivativeDefinitions($plugin_definition);
        foreach ($derivative_definitions as $derivative_id => $derivative_definition) {
          $plugin_id = $this->encodePluginId($base_plugin_id$derivative_id);
          // Use this definition as defaults if a plugin already defined           // itself as this derivative.           if ($derivative_id && isset($base_plugin_definitions[$plugin_id])) {
            $derivative_definition = $this->mergeDerivativeDefinition($base_plugin_definitions[$plugin_id]$derivative_definition);
          }
          $plugin_definitions[$plugin_id] = $derivative_definition;
        }
      }
      // If a plugin already defined itself as a derivative it might already
// Find the route name for the translation overview.       $translation_route_name = "entity.$entity_type_id.content_translation_overview";

      $base_route_name = "entity.$entity_type_id.canonical";
      $this->derivatives[$translation_route_name] = [
        'entity_type' => $entity_type_id,
        'title' => $this->t('Translate'),
        'route_name' => $translation_route_name,
        'base_route' => $base_route_name,
      ] + $base_plugin_definition;
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}

  protected $derivatives = [];

  /** * {@inheritdoc} */
  public function getDerivativeDefinition($derivative_id$base_plugin_definition) {
    if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
      return $this->derivatives[$derivative_id];
    }
    $this->getDerivativeDefinitions($base_plugin_definition);
    return $this->derivatives[$derivative_id];
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    return $this->derivatives;
  }

}
use Drupal\Component\Plugin\Derivative\DeriverInterface;

/** * Defines test derivative discovery. */
class TestDerivativeDiscovery implements DeriverInterface {

  /** * {@inheritdoc} */
  public function getDerivativeDefinition($derivative_id$base_plugin_definition) {
    $definitions = $this->getDerivativeDefinitions($base_plugin_definition);
    return $definitions[$derivative_id];
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $plugins = [];
    for ($i = 0; $i < 2; $i++) {
      $plugins['test_discovery_' . $i] = $base_plugin_definition;
    }
    
$this->derivatives[$entity_type . '.canonical'] = [];
      $this->derivatives[$entity_type . '.canonical']['base_route'] = "entity.$entity_type.canonical";
      $this->derivatives[$entity_type . '.canonical']['route_name'] = "entity.$entity_type.canonical";
      $this->derivatives[$entity_type . '.canonical']['title'] = 'View';

      $this->derivatives[$entity_type . '.edit'] = [];
      $this->derivatives[$entity_type . '.edit']['base_route'] = "entity.$entity_type.canonical";
      $this->derivatives[$entity_type . '.edit']['route_name'] = "entity.$entity_type.edit_form";
      $this->derivatives[$entity_type . '.edit']['title'] = 'Edit';
    }

    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}
      // plugin, which allows filtering the target entities by their label()       // method. The major downside of PhpSelection is that it is more expensive       // performance-wise than DefaultSelection because it has to load all the       // target entities in order to perform the filtering process, regardless       // of whether a limit has been passed.       // @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\PhpSelection       if (!$entity_type->hasKey('label')) {
        $this->derivatives[$entity_type_id]['class'] = 'Drupal\Core\Entity\Plugin\EntityReferenceSelection\PhpSelection';
      }
    }

    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}
'type' => 'entity_test_revpub',
        'label' => 'Delete test entity - revisions and publishing status',
        'action_label' => 'Delete',
        'confirm_form_route_name' => 'entity.entity_test_revpub.delete_multiple_form',
      ],
      'entity_test_rev' => [
        'type' => 'entity_test_rev',
        'label' => 'Delete test entity - revisions',
        'action_label' => 'Delete',
        'confirm_form_route_name' => 'entity.entity_test_rev.delete_multiple_form',
      ],
    ]$deriver->getDerivativeDefinitions([
      'action_label' => 'Delete',
    ]));
  }

  /** * @covers \Drupal\Core\Action\Plugin\Action\DeleteAction::execute */
  public function testDeleteAction() {
    $entity = EntityTestMulRevPub::create(['name' => 'test']);
    $entity->save();

    
Home | Imprint | This part of the site doesn't use cookies.