Skip to content

Commit

Permalink
Merge pull request #155 from bolt/hotfix/symfony-bolt-deprecations
Browse files Browse the repository at this point in the history
Symfony Forms 3 / Bolt 4 Compatibility — An unfinished Symphony
  • Loading branch information
rossriley committed Jul 17, 2017
2 parents 28d0416 + a942d97 commit ef3aa87
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/BoltForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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.
*
Expand Down
7 changes: 6 additions & 1 deletion src/Provider/BoltFormsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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
);
};

Expand Down

0 comments on commit ef3aa87

Please sign in to comment.