ProtectionRuleAddForm.php in User protect 8
File
src/Form/ProtectionRuleAddForm.php
View source
<?php
namespace Drupal\userprotect\Form;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ProtectionRuleAddForm extends ProtectionRuleFormBase {
public function buildForm(array $form, FormStateInterface $form_state, $protected_entity_type_id = 'user_role') {
switch ($protected_entity_type_id) {
case 'user':
case 'user_role':
break;
default:
throw new NotFoundHttpException();
}
$this->entity
->setProtectedEntityTypeId($protected_entity_type_id);
return parent::buildForm($form, $form_state);
}
public function save(array $form, FormStateInterface $form_state) {
parent::save($form, $form_state);
$this->messenger
->addMessage($this
->t('Added protection rule %name.', [
'%name' => $this->entity
->label(),
]));
}
}