NoteTypeForm.php in Drupal PM (Project Management) 4.x
File
modules/pm_note/src/Form/NoteTypeForm.php
View source
<?php
namespace Drupal\pm_note\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
class NoteTypeForm extends EntityForm {
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$pm_note_type = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $pm_note_type
->label(),
'#description' => $this
->t("Label for the Note type."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $pm_note_type
->id(),
'#machine_name' => [
'exists' => '\\Drupal\\pm_note\\Entity\\NoteType::load',
],
'#disabled' => !$pm_note_type
->isNew(),
];
return $form;
}
public function save(array $form, FormStateInterface $form_state) {
$pm_note_type = $this->entity;
$status = $pm_note_type
->save();
switch ($status) {
case SAVED_NEW:
$this
->messenger()
->addMessage($this
->t('Created the %label Note type.', [
'%label' => $pm_note_type
->label(),
]));
break;
default:
$this
->messenger()
->addMessage($this
->t('Saved the %label Note type.', [
'%label' => $pm_note_type
->label(),
]));
}
$form_state
->setRedirectUrl($pm_note_type
->toUrl('collection'));
}
}