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