Statistics
39
2
0
272d
Badges
Requirements

Build Status Latest Stable Version License Total Downloads Gitter

PresenterComponent

Tired from writing component factories? There is a solution!

1, Suppose, you have a form factory class:

namespace App\Forms;

use Nette;

class ProductFormFactory extends Nette\Object
{

	public function create()
	{
		$form = new Nette\Application\UI\Form;

		$form->onSuccess = [$this, 'succeeded'];

		return $form;
	}


	public function succeeded($form, $values)
	{
		# Your onSuccess code
	}

}

Than insted of:

namespace App\Prsenters;

use App;

class HomepagePresenter extends Nette\Application\UI\Presenter;
{

	/**
	 * @var App\Forms\ProductFormFactory
	 * @inject
	 */
	public $productFormFactory;


	public function createComponentProductForm()
	{
		return $this->productFormFactory->create();
	}

}

you can create form factory with annotation:

namespace App\Prsenters;

use App,
	Ublaboo\PresenterComponent\PresenterComponentTrait;

class HomepagePresenter extends Nette\Application\UI\Presenter;
{

	use PresenterComponentTrait;

	/**
	 * @var App\Forms\ProductFormFactory
	 * @inject
	 * @component productForm:create
	 */
	public $productFormFactory;

}

2, Passing variables to component factory class

namespace App\Prsenters;

use App,
	Ublaboo\PresenterComponent\PresenterComponentTrait;

class HomepagePresenter extends Nette\Application\UI\Presenter;
{

	public $id;

	use PresenterComponentTrait;

	/**
	 * @var App\Forms\ProductFormFactory
	 * @inject
	 * @component productForm:create
	 * @componentArgs id, user
	 */
	public $productFormFactory;

}

3, Form callbacks (onSuccess, onError, ..)

namespace App\Prsenters;

use App,
	Ublaboo\PresenterComponent\PresenterComponentTrait;

class HomepagePresenter extends Nette\Application\UI\Presenter;
{

	public $id;

	use PresenterComponentTrait;

	/**
	 * @var App\Forms\ProductFormFactory
	 * @inject
	 * @component productForm:create
	 * @componentArgs id, user
	 * @componentCallback onSuccess:succeeded
	 * @componentCallback onValidate:validate
	 * @componentCallback onError:formError
	 */
	public $productFormFactory;


	public function succeeded($form, $values)
	{

	}


	public function validate($form, $values)
	{
		
	}


	public function formError($form)
	{
		
	}

}

No release at this moment. Try to create first one.

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com