You are here

class HtmlEntityFormController in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/HtmlEntityFormController.php \Drupal\Core\Entity\HtmlEntityFormController

Wrapping controller for entity forms that serve as the main page body.

Hierarchy

Expanded class hierarchy of HtmlEntityFormController

1 string reference to 'HtmlEntityFormController'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses HtmlEntityFormController
controller.entity_form in core/core.services.yml
Drupal\Core\Entity\HtmlEntityFormController

File

core/lib/Drupal/Core/Entity/HtmlEntityFormController.php, line 18
Contains \Drupal\Core\Entity\HtmlEntityFormController.

Namespace

Drupal\Core\Entity
View source
class HtmlEntityFormController extends FormController {

  /**
   * The entity manager service.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * Constructs a new \Drupal\Core\Routing\Enhancer\FormEnhancer object.
   *
   * @param \Drupal\Core\Controller\ControllerResolverInterface $resolver
   *   The controller resolver.
   * @param \Drupal\Core\Form\FormBuilderInterface $form_builder
   *   The form builder.
   * @param \Drupal\Core\Entity\EntityManagerInterface $manager
   *   The entity manager.
   */
  public function __construct(ControllerResolverInterface $resolver, FormBuilderInterface $form_builder, EntityManagerInterface $manager) {
    parent::__construct($resolver, $form_builder);
    $this->entityManager = $manager;
  }

  /**
   * {@inheritdoc}
   */
  protected function getFormArgument(RouteMatchInterface $route_match) {
    return $route_match
      ->getRouteObject()
      ->getDefault('_entity_form');
  }

  /**
   * {@inheritdoc}
   *
   * Instead of a class name or service ID, $form_arg will be a string
   * representing the entity and operation being performed.
   * Consider the following route:
   * @code
   *   path: '/foo/{node}/bar'
   *   defaults:
   *     _entity_form: 'node.edit'
   * @endcode
   * This means that the edit form for the node entity will used.
   * If the entity type has a default form, only the name of the
   * entity {param} needs to be passed:
   * @code
   *   path: '/foo/{node}/baz'
   *   defaults:
   *     _entity_form: 'node'
   * @endcode
   */
  protected function getFormObject(RouteMatchInterface $route_match, $form_arg) {

    // If no operation is provided, use 'default'.
    $form_arg .= '.default';
    list($entity_type_id, $operation) = explode('.', $form_arg);
    $form_object = $this->entityManager
      ->getFormObject($entity_type_id, $operation);

    // Allow the entity form to determine the entity object from a given route
    // match.
    $entity = $form_object
      ->getEntityFromRouteMatch($route_match, $entity_type_id);
    $form_object
      ->setEntity($entity);
    return $form_object;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormController::$controllerResolver protected property The controller resolver.
FormController::$formBuilder protected property The form builder.
FormController::getContentResult public function Invokes the form and returns the result.
HtmlEntityFormController::$entityManager protected property The entity manager service.
HtmlEntityFormController::getFormArgument protected function Extracts the form argument string from a request. Overrides FormController::getFormArgument
HtmlEntityFormController::getFormObject protected function Instead of a class name or service ID, $form_arg will be a string representing the entity and operation being performed. Consider the following route: Overrides FormController::getFormObject
HtmlEntityFormController::__construct public function Constructs a new \Drupal\Core\Routing\Enhancer\FormEnhancer object. Overrides FormController::__construct