You are here

EntityGetInfo.php in Drupal 7 to 8/9 Module Upgrader 8

File

src/Plugin/DMU/Converter/Functions/EntityGetInfo.php
View source
<?php

namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions;

use Drupal\drupalmoduleupgrader\TargetInterface;
use Pharborist\Functions\FunctionCallNode;
use Pharborist\Objects\ClassMethodCallNode;

/**
 * @Converter(
 *  id = "entity_get_info",
 *  description = @Translation("Rewrites calls to entity_get_info().")
 * )
 */
class EntityGetInfo extends FunctionCallModifier {

  /**
   * {@inheritdoc}
   */
  public function rewrite(FunctionCallNode $call, TargetInterface $target) {
    $manager = ClassMethodCallNode::create('\\Drupal', 'entityTypeManager');
    $arguments = $call
      ->getArguments();
    if ($arguments
      ->isEmpty()) {
      return $manager
        ->appendMethodCall('getDefinitions');
    }
    elseif (sizeof($arguments) == 1) {
      return $manager
        ->appendMethodCall('getDefinition')
        ->appendArgument(clone $arguments[0]);
    }
  }

}

Classes

Namesort descending Description
EntityGetInfo Plugin annotation @Converter( id = "entity_get_info", description = @Translation("Rewrites calls to entity_get_info().") )