You are here

public function FormModeManagerConverter::convert in Form mode manager 8

Converts path variables to their corresponding objects.

Parameters

mixed $value: The raw value.

mixed $definition: The parameter definition provided in the route options.

string $name: The name of the parameter.

array $defaults: The route defaults array.

Return value

mixed|null The converted parameter value.

Overrides ParamConverterInterface::convert

File

src/ParamConverter/FormModeManagerConverter.php, line 38

Class

FormModeManagerConverter
Converter for form_mode_manager routes.

Namespace

Drupal\form_mode_manager\ParamConverter

Code

public function convert($value, $definition, $name, array $defaults) {
  $entity_type_id = $defaults['_route_object']
    ->getOption('_form_mode_manager_entity_type_id');
  $form_mode_id = $entity_type_id . '.' . $value;
  if ($form_mode_id === $defaults['_entity_form'] && $entity_type_id) {
    return $this->formModeManager
      ->getFormModesByEntity($entity_type_id)[$value];
  }
  return $value;
}