quiz-6.0.0-alpha4/src/Form/QuizTypeEntityForm.php
src/Form/QuizTypeEntityForm.php
<?php
namespace Drupal\quiz\Form;
use Drupal\Core\Entity\BundleEntityFormBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Quiz type authoring form.
*/
class QuizTypeEntityForm extends BundleEntityFormBase {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state): array {
$form = parent::form($form, $form_state);
$enrollment_type = $this->entity;
$form['label'] = [
'#title' => $this->t('Label'),
'#type' => 'textfield',
'#default_value' => $enrollment_type->label(),
'#description' => $this->t('The admin-facing name.'),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $enrollment_type->id(),
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
'#machine_name' => [
'exists' => '\Drupal\quiz\Entity\QuizType::load',
'source' => ['label'],
],
];
return $form;
}
}
