2017 © Pedro Peláez
 

library nette-general-form

Form general class for Nette Framework

image

geniv/nette-general-form

Form general class for Nette Framework

  • Tuesday, April 17, 2018
  • by geniv
  • Repository
  • 1 Watchers
  • 0 Stars
  • 302 Installations
  • PHP
  • 22 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 18 Versions
  • 56 % Grown

The README.md

Nette general form

Installation

$ composer require geniv/nette-general-form

or, (*1)

"geniv/nette-general-form": "^1.1"

require:, (*2)

"php": ">=7.0",
"nette/application": ">=2.4",
"nette/component-model": ">=2.3",
"nette/di": ">=2.4",
"nette/mail": ">=2.4",
"nette/utils": ">=2.4",
"tracy/tracy": ">=2.4"

Include in application

usage IEvent:, (*3)

class MyEvent implements IEvent

...

public function update(IEventContainer $eventContainer, array $values)

// usage method by IEventContainer
...
$eventContainer->getForm()
$eventContainer->addValues($values)
$eventContainer->setValues($values)
$eventContainer->removeValue($key)
$eventContainer->getComponent()
$eventContainer->getEventIndex()
$eventContainer->getEvents()

usage IFormContainer and _IEventContainer_ (can use magic __invoke method):, (*4)

private $formContainer;
private $eventContainer;
public $onSuccess, $onException;

public function __construct(IFormContainer $formContainer, array $events)

...

// $this->eventContainer = EventContainer::factory($this, $events, 'onSuccess', 'onException');
$this->eventContainer = EventContainer::factory($this, $events);
$this->formContainer = $formContainer;

...

$form->onSuccess[] = $this->eventContainer;

or the old way without __invoke:, (*5)

try {
    $this->notify($form, $values);
    $this->onSuccess($values);
} catch (EventException $e) {
    $this->onException($e);
}

usage _ITemplatePath_ (without return type!):, (*6)

class MyForm extends Control implements ITemplatePath

...

public function setTemplatePath(string $path)
{
    $this->templatePath = $path;
}

Events for use (implements IEvent)

- DumpEvent
- FireLogEvent
- ClearFormEvent
- SetValueEvent     (setValues(array))
- CallbackEvent     (onCallback(IEventContainer, array))
- EmailNotifyEvent  (getMessage(), setTemplatePath(string))

SetValueEvent

- SetValueEvent([active: false, role: guest])

CallbackEvent

- CallbackEvent

usage in presenter:, (*7)

$callbackEvent->onCallback[] = function (IEventContainer $eventContainer, array $value) {
    if ($this->identityModel->existLogin($value['login'])) {
        throw new EventException('duplicate login');
    }

    if ($this->identityModel->existEmail($value['email'])) {
        throw new EventException('duplicate email');
    }
};

EmailNotifyEvent

admin: Identity\Events\RegistrationEmailNotifyEvent     # email for admin
user: Identity\Events\RegistrationEmailNotifyEvent      # email for user
# or
- Identity\Events\ForgottenEmailNotifyEvent

where self class name (prevents multiple services in DI):, (*8)

class RegistrationEmailNotifyEvent extends EmailNotifyEvent {}
class ForgottenEmailNotifyEvent extends EmailNotifyEvent {}

usage in presenter:, (*9)

$emailNotifyEvent->onConfigure[] = function (IEventContainer $eventContainer, array $value) use ($emailNotifyEvent) {
    $emailNotifyEvent->setTemplatePath(__DIR__ . '/templates/Forgotten/emailFormForgotten.latte');

    $message = $emailNotifyEvent->getMessage();
    $message->setFrom('info@email.cz');

    $message->setSubject('informacni email pro uzivatele');
    $message->addTo($value['email']);
};

// or

$emailNotifyEvent->onConfigure[] = function (IEventContainer $eventContainer, array $value) use ($emailNotifyEvent) {
    $message = $emailNotifyEvent->getMessage();
    $message->setFrom('info@email.cz');

    switch ($eventContainer->getEventIndex()) {
        case 'user':
            $emailNotifyEvent->setTemplatePath(__DIR__ . '/templates/Registration/emailFormUser.latte');

            $message->setSubject('informacni email pro uzivatele');
            $message->addTo($value['email']);
            break;

        case 'admin':
            $emailNotifyEvent->setTemplatePath(__DIR__ . '/templates/Registration/emailFormAdmin.latte');

            $message->setSubject('informacni email pro admina');
            $message->addTo('email@email.com');
            break;
    }
};

event in definition is possible use several times, and define like anonymous index or text index, (*10)

events:
    - DumpEvent
    - DumpEvent
    fire1: FireLogEvent
    fire2: FireLogEvent

Extension

usage GeneralForm:, (*11)

$formContainer = GeneralForm::getDefinitionFormContainer($this);
$events = GeneralForm::getDefinitionEventContainer($this);

usage GeneralControl:, (*12)

class MyForm extends GeneralControl {

    public function __construct(IFormContainer $formContainer, array $events, ITranslator $translator = null)
    {
        parent::__construct($formContainer, $events, $translator);

        $this->templatePath = __DIR__ . '/MyPath.latte';    // set path
    }
}

Exception

class: EventException, (*13)

The Versions

17/04 2018

dev-master

9999999-dev

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

17/04 2018

v1.1.5

1.1.5.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

17/04 2018

dev-develop

dev-develop

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

16/04 2018

v1.1.4

1.1.4.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

16/04 2018

v1.1.3

1.1.3.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

16/04 2018

v1.1.2

1.1.2.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

15/04 2018

v1.1.1

1.1.1.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

15/04 2018

v1.1.0

1.1.0.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

28/02 2018

v1.0.9

1.0.9.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

24/02 2018

v1.0.8

1.0.8.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

24/02 2018

v1.0.7

1.0.7.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

21/02 2018

v1.0.6

1.0.6.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

17/02 2018

v1.0.5

1.0.5.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

16/02 2018

v1.0.4

1.0.4.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

15/02 2018

v1.0.3

1.0.3.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

14/02 2018

v1.0.2

1.0.2.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

14/02 2018

v1.0.1

1.0.1.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer

14/02 2018

v1.0.0

1.0.0.0

Form general class for Nette Framework

  Sources   Download

MIT

The Requires

 

by Radek Frystak

content event nette geniv eventcontainer formcontainer