You are here

public function FormConverterFactory::get in Drupal 7 to 8/9 Module Upgrader 8

Creates a FormConverter for a specific form.

Parameters

\Drupal\drupalmoduleupgrader\TargetInterface $target: The module which defines the form.

string $form_id: The original form ID.

Return value

FormConverter

Throws

\BadMethodCallException if the target module doesn't define the given form.

File

src/Utility/FormConverterFactory.php, line 37

Class

FormConverterFactory

Namespace

Drupal\drupalmoduleupgrader\Utility

Code

public function get(TargetInterface $target, $form_id) {
  $indexer = $target
    ->getIndexer('function');
  if ($indexer
    ->has($form_id)) {
    return new FormConverter($target, $form_id, $this->rewriter);
  }
  else {
    $message = $this
      ->t('@target does not define form @form_id.', [
      '@target' => $target
        ->id(),
      '@form_id' => $form_id,
    ]);
    throw new \BadMethodCallException($message);
  }
}