You are here

public function FormModeManager::setFormClassPerFormModes in Form mode manager 8.2

Same name and namespace in other branches
  1. 8 src/FormModeManager.php \Drupal\form_mode_manager\FormModeManager::setFormClassPerFormModes()

Set new FormClass handler per form modes keyed by form mode name.

This setter are the best way to alter the basic FormClass, for specific operation (form mode)

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_definition: The entity type to alter.

string $form_mode_name: The form mode human name used by current entity definition.

Overrides FormModeManagerInterface::setFormClassPerFormModes

See also

http://bit.ly/2sL5L7W .

1 call to FormModeManager::setFormClassPerFormModes()
FormModeManager::setEntityHandlersPerFormModes in src/FormModeManager.php
Set all entity handlers needed by form mode manager on entity type basis.

File

src/FormModeManager.php, line 333

Class

FormModeManager
FormDisplayManager service.

Namespace

Drupal\form_mode_manager

Code

public function setFormClassPerFormModes(EntityTypeInterface $entity_definition, $form_mode_name) {
  $entity_type_id = $entity_definition
    ->id();

  /** @var \Drupal\form_mode_manager\EntityRoutingMapBase $route_mapper_plugin */
  $route_mapper_plugin = $this->entityRoutingMap
    ->createInstance($entity_type_id, [
    'entityTypeId' => $entity_type_id,
  ]);
  if ($default_form = $entity_definition
    ->getFormClass($route_mapper_plugin
    ->getDefaultFormClass())) {
    $entity_definition
      ->setFormClass($this
      ->enhanceFormClassName('default', $form_mode_name), $default_form);
  }
  if ($edit_form = $entity_definition
    ->getFormClass($route_mapper_plugin
    ->getEditFormClass())) {
    $entity_definition
      ->setFormClass($this
      ->enhanceFormClassName('edit', $form_mode_name), $edit_form);
  }
}