ContentTypeConfigForm.php in Content Planner 8
File
modules/content_calendar/src/Form/ContentTypeConfigForm.php
View source
<?php
namespace Drupal\content_calendar\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
class ContentTypeConfigForm extends EntityForm {
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$config_entity = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $config_entity
->label(),
'#description' => $this
->t("Label for the Content Type Config."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $config_entity
->id(),
'#machine_name' => [
'exists' => '\\Drupal\\content_calendar\\Entity\\ContentTypeConfig::load',
],
'#disabled' => !$config_entity
->isNew(),
];
$form['color'] = [
'#type' => 'textfield',
'#title' => $this
->t('Color'),
'#maxlength' => 20,
'#default_value' => $config_entity
->getColor(),
'#description' => $this
->t("The color value to use for this Content Type inside the Content Calendar. Examples: #ffcc00 or 'red'."),
'#required' => TRUE,
];
return $form;
}
public function save(array $form, FormStateInterface $form_state) {
$config_entity = $this->entity;
$status = $config_entity
->save();
switch ($status) {
case SAVED_NEW:
$this
->messenger()
->addMessage($this
->t('Created the %label Content Type Config.', [
'%label' => $config_entity
->label(),
]));
break;
default:
$this
->messenger()
->addMessage($this
->t('Saved the %label Content Type Config.', [
'%label' => $config_entity
->label(),
]));
}
$form_state
->setRedirectUrl($config_entity
->toUrl('collection'));
}
}