NodeLimitForm.php in Node Limit 8
File
src/Form/NodeLimitForm.php
View source
<?php
namespace Drupal\node_limit\Form;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
class NodeLimitForm extends EntityForm {
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$node_limit = $this->entity;
$form['label'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $node_limit
->label(),
'#description' => $this
->t("Label for the NodeLimit."),
'#required' => TRUE,
);
$form['id'] = array(
'#type' => 'machine_name',
'#default_value' => $node_limit
->id(),
'#machine_name' => array(
'exists' => '\\Drupal\\node_limit\\Entity\\NodeLimit::load',
),
'#disabled' => !$node_limit
->isNew(),
);
return $form;
}
public function save(array $form, FormStateInterface $form_state) {
$node_limit = $this->entity;
$status = $node_limit
->save();
if ($status) {
$this
->messenger()
->addStatus($this
->t('Saved the %label NodeLimit.', array(
'%label' => $node_limit
->label(),
)));
}
else {
$this
->messenger()
->addStatus($this
->t('The %label NodeLimit was not saved.', array(
'%label' => $node_limit
->label(),
)));
}
$form_state
->setRedirect('entity.node_limit.list');
}
}