ticket-8.x-1.x-dev/src/Form/RegistrationForm.php

src/Form/RegistrationForm.php
<?php

namespace Drupal\ticket\Form;

use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;

/**
 * Form controller for Registration edit forms.
 *
 * @ingroup ticket
 */
class RegistrationForm extends ContentEntityForm {

  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $registration = $this->entity;
    $form = parent::form($form, $form_state);
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function save(array $form, FormStateInterface $form_state) {
    $registration = $this->entity;

    $status = parent::save($form, $form_state);

    switch ($status) {
      case SAVED_NEW:
        $this->messenger()->addStatus($this->t('Created the %label Registration.', [
          '%label' => $registration->label(),
        ]));
        break;

      default:
        $this->messenger()->addStatus($this->t('Saved the %label Registration.', [
          '%label' => $registration->label(),
        ]));
    }
    $form_state->setValue('registrationId', $registration->id());
    $form_state->set('registrationId', $registration->id());
    $form_state->setRedirect('entity.registration.canonical', ['registration' => $registration->id()]);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc