public function EntityFormModeBase::entityAdd in Form mode manager 8
Provides the entity add submission form.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.
Return value
array The entity add Form.
1 method overrides EntityFormModeBase::entityAdd()
- UserFormModeController::entityAdd in src/
Controller/ UserFormModeController.php - Provides the entity submission form.
File
- src/
Controller/ EntityFormModeBase.php, line 201
Class
- EntityFormModeBase
- Controller for entity form mode support.
Namespace
Drupal\form_mode_manager\ControllerCode
public function entityAdd(RouteMatchInterface $route_match) {
/* @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $this
->getEntityFromRouteMatch($route_match);
if (empty($entity)) {
$route_entity_type_info = $this
->getEntityTypeFromRouteMatch($route_match);
/* @var \Drupal\Core\Entity\EntityInterface $entity */
$entity = $this->entityTypeManager
->getStorage($route_entity_type_info['entity_type_id'])
->create([
$route_entity_type_info['entity_key'] => $route_entity_type_info['bundle'],
]);
}
$form_mode_id = $this->formModeManager
->getFormModeMachineName($route_match
->getRouteObject()
->getDefault('_entity_form'));
$operation = empty($form_mode_id) ? 'default' : $form_mode_id;
if ($entity instanceof EntityInterface) {
return $this->entityFormBuilder
->getForm($entity, $operation);
}
}