2017 © Pedro Peláez
 

library forms

Venne forms component

image

venne/forms

Venne forms component

  • Tuesday, March 3, 2015
  • by pepakriz
  • Repository
  • 2 Watchers
  • 0 Stars
  • 125 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Venne:Forms Build Status

Create forms as nested factories:, (*1)

+- IFormFactory ---+    +- IFormFactory --+    +- IFormFactory -+
|   Base factory   | -> |   Adds inputs   | -> |  Adds mapping  | -> create() : Form
+------------------+    +-----------------+    +----------------+

Benefits:, (*2)

  • Change form configuration around the application on one place.
  • Each factory can be used independently.
  • It is not necessary to inherit forms.

Installation

The best way to install Venne/Forms is using Composer:, (*3)

composer require venne/forms:@dev

Usage

Create basic factory

example:, (*4)

services:
    basicFormFactory:
        class: Nette\Application\UI\Form
        arguments: [NULL, NULL]
        implement: Venne\Forms\IFormFactory
        setup:
            - setRenderer(@system.formRenderer)
            - setTranslator(@translator.translator)
        autowired: no

Create forms as factory

Implement Venne\Forms\IFormFactory:, (*5)

class FooFormFactory implements Venne\Forms\IFormFactory
{

    private $formFactory;


    public function __construct(IFormFactory $formFactory)
    {
        $this->formFactory = $formFactory;
    }


    public function create()
    {
        $form = $this->formFactory->create();
        $form->addText('foo', 'Foo');
        $form->addSubmit('_submit', 'Save');
        return $form;
    }

}

Register forms

Define nested formFactory in constructor, (*6)

services:
    fooFormFactory:
        class: FooFormFactory(@basicFormFactory)

Use it in presenter

class ExamplePresenter extends Nette\Application\UI\Presenter
{

    private $fooFormFactory;

    public function __construct(FooFormFactory $fooFormFactory)
    {
        $this->fooFormFactory = $fooFormFactory;
    }

    public function createComponentFooForm()
    {
        $form = $this->fooFormFactory->create();
        $form->onSuccess[] = $this->fooFormSuccess;
        return $form;
    }

    public function fooFormSuccess($form)
    {
        ...
    }

}

Connect forms with kdyby\doctrine-forms

```php use Venne\Bridges\Kdyby\DoctrineForms\FormFactoryFactory;, (*7)

class ExamplePresenter extends Nette\Application\UI\Presenter {, (*8)

private $fooFormFactory;
private $formFactoryFactory;

public function __construct(FooFormFactory $fooFormFactory, FormFactoryFactory $formFactoryFactory)
{
    $this->fooFormFactory = $fooFormFactory;
    $this->formFactoryFactory = $formFactoryFactory;
}

public function createComponentFooForm()
{
    $entity = ....;

    $form = $this->formFactoryFactory
                ->create($this->fooFormFactory)
                ->setEntity($entity)
                ->create();

    $form->onSuccess[] = $this->fooFormSuccess;
    return $form;
}

public function fooFormSuccess($form)
{
    ...
}

}, (*9)

The Versions

03/03 2015

dev-master

9999999-dev http://venne.cz

Venne forms component

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

forms nette venne