PopupOnLoadForm.php in Popup On Load 8
File
src/Form/PopupOnLoadForm.php
View source
<?php
namespace Drupal\popup_onload\Form;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PopupOnLoadForm extends ContentEntityForm {
protected $messenger;
public function __construct(EntityRepositoryInterface $entity_repository, MessengerInterface $messenger, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time = NULL);
$this->messenger = $messenger;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.repository'), $container
->get('messenger'), $container
->get('entity_type.bundle.info'), $container
->get('datetime.time'));
}
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
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
->addMessage($this
->t('Created the %label Popup On Load.', [
'%label' => $entity
->label(),
]));
break;
default:
$this->messenger
->addMessage($this
->t('Saved the %label Popup On Load.', [
'%label' => $entity
->label(),
]));
}
$form_state
->setRedirect('entity.popup_onload.collection');
}
}