You are here

public function FormConverter::build in Drupal 7 to 8/9 Module Upgrader 8

Return value

\Pharborist\Objects\ClassNode

File

src/Utility/FormConverter.php, line 108

Class

FormConverter
Converts a form from a set of callback functions to a class implementing \Drupal\Core\Form\FormInterface.

Namespace

Drupal\drupalmoduleupgrader\Utility

Code

public function build() {
  $controller = $this
    ->render();
  $builder = $this
    ->addMethod($this->builder, $controller, 'buildForm');
  if ($this->isConfig) {
    $builder
      ->find(Filter::isFunctionCall('system_settings_form'))
      ->each(function (FunctionCallNode $call) {
      $call
        ->setName('parent::buildForm')
        ->appendArgument(Token::variable('$form_state'));
    });
  }
  if ($this->validator) {
    $this
      ->addMethod($this->validator, $controller, 'validateForm')
      ->getParameterAtIndex(0)
      ->setReference(TRUE)
      ->setTypeHint('array');
  }
  if ($this->submitHandler) {
    $this
      ->addMethod($this->submitHandler, $controller, $this->isConfig ? '_submitForm' : 'submitForm')
      ->getParameterAtIndex(0)
      ->setReference(TRUE)
      ->setTypeHint('array');
  }
  return $controller;
}