public function ProtectionRuleAddForm::buildForm in User protect 8
Overrides EntityFormController::buildForm().
Sets protected entity type on protection rule entity.
Parameters
array $form: Nested array of form elements that comprise the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
string $protected_entity_type_id: (optional) The entity type to protect. Defaults to 'user_role'.
Overrides EntityForm::buildForm
File
- src/
Form/ ProtectionRuleAddForm.php, line 26
Class
- ProtectionRuleAddForm
- Provides a form controller for adding a protection rule.
Namespace
Drupal\userprotect\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $protected_entity_type_id = 'user_role') {
// Only allow entity types 'user' and '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);
}