3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions;
5 use Drupal\Core\StringTranslation\TranslationInterface;
6 use Drupal\drupalmoduleupgrader\DeriverBase;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
10 * Builds derivative definitions for the _entity_operation plugin, allowing us to
11 * rewrite calls to things like entity_save(), node_delete(), entity_label(), etc.
13 class EntityOperationDeriver extends DeriverBase {
20 public function __construct(TranslationInterface $translator, array $config) {
21 parent::__construct($translator);
22 $this->config = $config;
28 public static function create(ContainerInterface $container, $base_plugin_id) {
30 $container->get('string_translation'),
31 $container->get('config.factory')->get('drupalmoduleupgrader.entity_operations')->get('definitions')
38 public function getDerivativeDefinitions($base_definition) {
41 foreach ($this->config as $entity_type => $operations) {
42 foreach ($operations as $operation) {
43 $function = $entity_type . '_' . $operation;
45 '@function' => $function,
46 '@operation' => $operation,
48 $derivative = $base_definition;
49 $derivative['function'] = $function;
50 $derivative['method'] = $operation;
51 $derivative['message'] = $this->t('`@function` is now `EntityInterface::@operation`.', $variables);
52 $derivative['description'] = $this->t('Rewrites calls to @function().', $variables);
53 $derivatives[$function] = $derivative;