InviteForm.php in Invite 8
File
src/Form/InviteForm.php
View source
<?php
namespace Drupal\invite\Form;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class InviteForm extends ContentEntityForm {
protected $messenger;
public function __construct(EntityManagerInterface $entity_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL, MessengerInterface $messenger) {
parent::__construct($entity_manager, $entity_type_bundle_info, $time);
$this->messenger = $messenger;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.manager'), $container
->get('entity_type.bundle.info'), $container
->get('datetime.time'), $container
->get('messenger'));
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$entity = $this->entity;
return $form;
}
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$status = parent::save($form, $form_state);
switch ($status) {
case SAVED_NEW:
$this->messenger
->addStatus($this
->t('Created the %label Invite.', [
'%label' => $entity
->label(),
]));
break;
default:
$this->messenger
->addStatus($this
->t('Saved the %label Invite.', [
'%label' => $entity
->label(),
]));
}
$form_state
->setRedirect('entity.invite.canonical', [
'invite' => $entity
->id(),
]);
}
}