You are here

QuizFeedbackTypeForm.php in Quiz 8.5

Same filename and directory in other branches
  1. 8.6 src/Entity/QuizFeedbackTypeForm.php

Namespace

Drupal\quiz\Entity

File

src/Entity/QuizFeedbackTypeForm.php
View source
<?php

namespace Drupal\quiz\Entity;

use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;

/**
 * Edit form for feedback types.
 */
class QuizFeedbackTypeForm extends EntityForm {

  /**
   * {@inheritdoc}
   */
  public function form(array $form, FormStateInterface $form_state) {
    $form['label'] = [
      '#title' => t('Label'),
      '#type' => 'textfield',
      '#default_value' => $this->entity
        ->label(),
      '#description' => t('The admin-facing name.'),
      '#required' => TRUE,
    ];
    $form['id'] = [
      '#type' => 'machine_name',
      '#default_value' => $this->entity
        ->id(),
      '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
      '#machine_name' => [
        'exists' => get_class($this->entity) . '::load',
        'source' => [
          'label',
        ],
      ],
    ];
    $form['description'] = [
      '#title' => t('Description'),
      '#type' => 'textarea',
      '#default_value' => $this->entity
        ->get('description'),
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function save(array $form, FormStateInterface $form_state) {
    parent::save($form, $form_state);
    $form_state
      ->setRedirect('entity.quiz_feedback_type.collection');
  }

}

Classes

Namesort descending Description
QuizFeedbackTypeForm Edit form for feedback types.