function entity_form_controller

Returns an entity form controller for the given operation.

Since there might be different scenarios in which an entity is edited, multiple form controllers suitable to the different operations may be defined. If no controller is found for the default operation, the base class will be used. If a non-existing non-default operation is specified an exception will be thrown.

Parameters

$entity_type: The type of the entity.

$operation: (optional) The name of an operation, such as creation, editing or deletion, identifying the controlled form. Defaults to 'default' which is the usual create/edit form.

Return value

Drupal\Core\Entity\EntityFormControllerInterface An entity form controller instance.

See also

\Drupal\Core\Entity\EntityManager

1 call to entity_form_controller()
entity_form_state_defaults in drupal/core/includes/entity.inc
Returns the default form state for the given entity and operation.

File

drupal/core/includes/entity.inc, line 349
Entity API for handling entities like nodes or users.

Code

function entity_form_controller($entity_type, $operation = 'default') {
  $info = entity_get_info($entity_type);

  // Check whether there is a form controller class for the specified operation.
  if (!empty($info['form_controller_class'][$operation])) {
    $class = $info['form_controller_class'][$operation];
  }
  elseif (empty($info['form_controller_class']) && $operation == 'default') {
    $class = 'Drupal\\Core\\Entity\\EntityFormController';
  }
  else {
    throw new InvalidArgumentException("Missing form controller for '{$entity_type}', operation '{$operation}'");
  }
  return new $class($operation);
}