public function AbstractEntityFormModesFactory::getOperation in Form mode manager 8.2
Return the correct form mode name for given contexts ($op).
To separate things Form mode manager need to contextualize form mode by, operation (edit). Because this module permit to make difference and, override FormClass used by add/edit operation. In drupal add and edit, are declared in annotation at EntityPlugin basis but this module make, possible to change that annotation and use form mode specifically, for one form mode.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.
string $entity_type_id: The type of $entity; e.g. 'node' or 'user'.
string $op: The entity form operation name.
Return value
string The correct form mode name depends of given operation.
Throws
\Exception If an invalid entity is retrieving from the route object.
2 calls to AbstractEntityFormModesFactory::getOperation()
- AbstractEntityFormModesFactory::entityAdd in src/
AbstractEntityFormModesFactory.php - Provides the entity add submission form.
- AbstractEntityFormModesFactory::entityEdit in src/
AbstractEntityFormModesFactory.php - Provides the entity 'edit' form.
File
- src/
AbstractEntityFormModesFactory.php, line 314
Class
- AbstractEntityFormModesFactory
- Abstract Factory to generate object used by routing of Form Mode Manager.
Namespace
Drupal\form_mode_managerCode
public function getOperation(RouteMatchInterface $route_match, $entity_type_id, $op = '') {
$form_mode_id = $this->formModeManager
->getFormModeMachineName($route_match
->getRouteObject()
->getOption('parameters')['form_mode']['id']);
/** @var \Drupal\form_mode_manager\EntityRoutingMapBase $entity_routes_infos */
$entity_routes_infos = $this->entityRoutingMap
->createInstance($entity_type_id, [
'entityTypeId' => $entity_type_id,
])
->getPluginDefinition();
if ($op === 'edit') {
return empty($form_mode_id) ? $entity_routes_infos
->getDefaultFormClass() : FormModeManagerInterface::EDIT_PREFIX . $form_mode_id;
}
return empty($form_mode_id) ? $entity_routes_infos
->getDefaultFormClass() : FormModeManagerInterface::ADD_PREFIX . $form_mode_id;
}