<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Bundle\ResourceBundle\Controller;
use Sylius\Component\Resource\Model\ResourceInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
final class ResourceFormFactory implements ResourceFormFactoryInterface
{
/** @var FormFactoryInterface */
private $formFactory;
public function __construct(FormFactoryInterface $formFactory)
{
$this->formFactory = $formFactory;
}
public function create(RequestConfiguration $requestConfiguration, ResourceInterface $resource): FormInterface
{
$formType = (string) $requestConfiguration->getFormType();
$formOptions = $requestConfiguration->getFormOptions();
if ($requestConfiguration->isHtmlRequest()) {
return $this->formFactory->create($formType, $resource, $formOptions);
}
return $this->formFactory->createNamed('', $formType, $resource, array_merge($formOptions, ['csrf_protection' => false]));
}
}