From 53d784c97dd08e63773b9d0cd53cef7c5ece2d49 Mon Sep 17 00:00:00 2001 From: Gawain Lynch Date: Mon, 17 Jul 2017 10:44:39 +0200 Subject: [PATCH 1/2] Attempt to get field type FQCN --- src/BoltForms.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/BoltForms.php b/src/BoltForms.php index c240a91..ed64882 100644 --- a/src/BoltForms.php +++ b/src/BoltForms.php @@ -118,7 +118,7 @@ public function create($formName, $type = BoltFormType::class, $data = null, $op /** @var Config\FormConfig $formConfig */ $formConfig = $this->config->getForm($formName); foreach ($formConfig->getFields()->all() as $key => $field) { - $builder->add($key, $field['type'], $field['options']); + $builder->add($key, $this->getTypeClassName($field['type']), $field['options']); } /** @var Form $form */ @@ -134,6 +134,23 @@ public function create($formName, $type = BoltFormType::class, $data = null, $op return $this->forms[$formName]; } + /** + * Return the FQCN of the Symfony Form type, or just the string if not found. + * + * @param string $type + * + * @return string + */ + private function getTypeClassName($type) + { + $className = 'Symfony\\Component\\Form\\Extension\\Core\\Type\\' . ucwords($type) . 'Type'; + if (class_exists($className)) { + return $className; + } + + return $type; + } + /** * Get a particular form. * From a942d97027f43142cfe612c1557cb5365f57c98a Mon Sep 17 00:00:00 2001 From: Gawain Lynch Date: Mon, 17 Jul 2017 10:46:54 +0200 Subject: [PATCH 2/2] Use path_resolver for Bolt 3.3+ --- src/Provider/BoltFormsServiceProvider.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Provider/BoltFormsServiceProvider.php b/src/Provider/BoltFormsServiceProvider.php index 3d1f641..d57f8fc 100644 --- a/src/Provider/BoltFormsServiceProvider.php +++ b/src/Provider/BoltFormsServiceProvider.php @@ -142,6 +142,11 @@ private function registerTwig(Application $app) } $app['twig.runtime.boltforms'] = function ($app) { + $rootPath = version_compare(BoltVersion::forComposer(), '3.3.0', '<') + ? $app['resources']->getPath('root') + : $app['path_resolver']->resolve('%root%') + ; + return new Twig\Extension\BoltFormsRuntime( $app['boltforms'], $app['boltforms.config'], @@ -153,7 +158,7 @@ private function registerTwig(Application $app) $app['logger.system'], $app['url_generator'], $app['extensions']->get('bolt/boltforms')->getWebDirectory()->getPath(), - $app['resources']->getPath('root') + $rootPath ); };