You are here

public function FormCallbackToMethod::execute in Drupal 7 to 8/9 Module Upgrader 8

Executes the plugin.

Overrides ExecutableInterface::execute

File

src/Plugin/DMU/Fixer/FormCallbackToMethod.php, line 14

Class

FormCallbackToMethod
Plugin annotation @Fixer( id = "form_callback_to_method" )

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Fixer

Code

public function execute() {

  /** @var \Pharborist\Functions\FunctionDeclarationNode $callback */
  $callback = $this->target
    ->getIndexer('function')
    ->get($this->configuration['callback']);
  list($class, $method_name) = explode('::', $this->configuration['destination']);

  /** @var \Pharborist\Objects\ClassNode $class */
  $class = $this->target
    ->getIndexer('class')
    ->get($class);
  $method = $callback
    ->cloneAsMethodOf($class)
    ->setName($method_name);
  $form_interface = new \ReflectionClass('\\Drupal\\Core\\Form\\FormInterface');
  if ($form_interface
    ->hasMethod($method_name)) {
    $method
      ->matchReflector($form_interface
      ->getMethod($method_name));
  }
  $this->target
    ->save($method);
}