Skip to content

Provides a form ordering support with the Symfony2 form component.

License

Notifications You must be signed in to change notification settings

WandiParis/ivory-ordered-form

 
 

Repository files navigation

README

Travis Build Status AppVeyor Build status Code Coverage Scrutinizer Code Quality Dependency Status

Latest Stable Version Latest Unstable Version Total Downloads License

The library allows to order your Symfony2 form fields by adding the position option. A position can either be first, last or an associative array describing before and/or after field.

Wandi Note

Note: this is a Symfony 4 Fork

If you want to use this Bundle with the Symfony Framework Standard Edition and use the CreateForm method in a Controller that extends Symfony\Bundle\FrameworkBundle\Controller\AbstractController, follow this quick guide:

// config/services.yaml
Symfony\Component\Form\FormExtensionInterface: "@form.extension"

Before (classic case):

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class YourController extends AbstractController
{
    // [...]
    
    public function __construct(/* DI */)
    {
        // [...]
    }
    
    public function yourAction(Request $request): Response
    {
        $yourEntity = new Entity();
        
        $form = $this->createForm(YourType::class, $yourEntity, [
            // your options
        ]);
        $form->handleRequest($request);
        
         // [...]
    }
}

After:

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Form\FormExtensionInterface;
use Ivory\OrderedForm\Extension\OrderedExtension;
use Symfony\Component\Form\Forms;
use Ivory\OrderedForm\OrderedResolvedFormTypeFactory;

class YourController extends AbstractController
{
    /**
     * @var FormExtensionInterface
     */
    private $formExtension;
    
    public function __construct(FormExtensionInterface $formExtension)
    {
        $this->formExtension = $formExtension;
    }
    
    public function yourAction(Request $request): Response
    {
        $yourEntity = new Entity();
        
        $formFactory = Forms::createFormFactoryBuilder()
            ->setResolvedTypeFactory(new OrderedResolvedFormTypeFactory())
            ->addExtension($this->formExtension)
            ->addExtension(new OrderedExtension())
            ->getFormFactory();
        $form = $formFactory->create(YourType::class, $yourEntity, [
            // your options
        ]);
        $form->handleRequest($request);
        
         // [...]
    }
}

Documentation

  1. Installation
  2. Usage
  3. Known limitations

Testing

The library is fully unit tested by PHPUnit with a code coverage close to 100%. To execute the test suite, check the travis configuration.

Contribute

We love contributors! Ivory is an open source project. If you'd like to contribute, feel free to propose a PR! You can follow the CONTRIBUTING file which will explain you how to set up the project.

License

The Ivory Ordered Form is under the MIT license. For the full copyright and license information, please read the LICENSE file that was distributed with this source code.

About

Provides a form ordering support with the Symfony2 form component.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 94.0%
  • Shell 3.9%
  • Dockerfile 2.1%