You are here

class EntityOperationDeriver in Drupal 7 to 8/9 Module Upgrader 8

Builds derivative definitions for the _entity_operation plugin, allowing us to rewrite calls to things like entity_save(), node_delete(), entity_label(), etc.

Hierarchy

Expanded class hierarchy of EntityOperationDeriver

File

src/Plugin/DMU/Converter/Functions/EntityOperationDeriver.php, line 13

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions
View source
class EntityOperationDeriver extends DeriverBase {

  /**
   * @var array
   */
  protected $config;
  public function __construct(TranslationInterface $translator, array $config) {
    parent::__construct($translator);
    $this->config = $config;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('string_translation'), $container
      ->get('config.factory')
      ->get('drupalmoduleupgrader.entity_operations')
      ->get('definitions'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_definition) {
    $derivatives = [];
    foreach ($this->config as $entity_type => $operations) {
      foreach ($operations as $operation) {
        $function = $entity_type . '_' . $operation;
        $variables = [
          '@function' => $function,
          '@operation' => $operation,
        ];
        $derivative = $base_definition;
        $derivative['function'] = $function;
        $derivative['method'] = $operation;
        $derivative['message'] = $this
          ->t('`@function` is now `EntityInterface::@operation`.', $variables);
        $derivative['description'] = $this
          ->t('Rewrites calls to @function().', $variables);
        $derivatives[$function] = $derivative;
      }
    }
    return $derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
EntityOperationDeriver::$config protected property
EntityOperationDeriver::create public static function Creates a new class instance. Overrides DeriverBase::create
EntityOperationDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverInterface::getDerivativeDefinitions
EntityOperationDeriver::__construct public function Overrides DeriverBase::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.