X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FUtility%2FFormConverterFactory.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Fsrc%2FUtility%2FFormConverterFactory.php;h=de35ebf36a54f4022130804f15d05fef58988bd5;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Utility/FormConverterFactory.php b/web/modules/contrib/drupalmoduleupgrader/src/Utility/FormConverterFactory.php new file mode 100644 index 000000000..de35ebf36 --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/src/Utility/FormConverterFactory.php @@ -0,0 +1,52 @@ +stringTranslation = $translator; + $this->rewriter = $rewriters->createInstance('form_state'); + } + + /** + * Creates a FormConverter for a specific form. + * + * @param 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); + } + } + +}