FormConverterFactory.php in Drupal 7 to 8/9 Module Upgrader 8
Namespace
Drupal\drupalmoduleupgrader\UtilityFile
src/Utility/FormConverterFactory.phpView source
<?php
namespace Drupal\drupalmoduleupgrader\Utility;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\drupalmoduleupgrader\TargetInterface;
class FormConverterFactory {
use StringTranslationTrait;
/**
* @var \Drupal\drupalmoduleupgrader\RewriterInterface
*/
protected $rewriter;
public function __construct(TranslationInterface $translator, PluginManagerInterface $rewriters) {
$this->stringTranslation = $translator;
$this->rewriter = $rewriters
->createInstance('form_state');
}
/**
* Creates a FormConverter for a specific form.
*
* @param \Drupal\drupalmoduleupgrader\TargetInterface $target
* The module which defines the form.
* @param string $form_id
* The original form ID.
*
* @return FormConverter
*
* @throws \BadMethodCallException if the target module doesn't define
* the given form.
*/
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);
}
}
}
Classes
Name | Description |
---|---|
FormConverterFactory |