You are here

class SimpleEntityFormModes in Form mode manager 8.2

Route controller factory specific for each entities not using bundles.

This Factory are specific to work with entities NOT USING bundles and, need more specific code to implement it.

Hierarchy

Expanded class hierarchy of SimpleEntityFormModes

1 file declares its use of SimpleEntityFormModes
FormModeManagerEntityController.php in src/Controller/FormModeManagerEntityController.php

File

src/SimpleEntityFormModes.php, line 14

Namespace

Drupal\form_mode_manager
View source
class SimpleEntityFormModes extends AbstractEntityFormModesFactory {

  /**
   * {@inheritdoc}
   *
   * In simple entities without bundles we don't generate add_page routes.
   */
  public function addPage(RouteMatchInterface $route_match) {
  }

  /**
   * {@inheritdoc}
   */
  public function checkAccess(RouteMatchInterface $route_match) {

    /** @var \Drupal\Core\Entity\EntityInterface $entity */
    $entity = $this
      ->getEntityFromRouteMatch($route_match);
    $route = $route_match
      ->getRouteObject();
    $form_mode_id = $route
      ->getDefault('_entity_form');
    $cache_tags = $this->formModeManager
      ->getListCacheTags();

    // When we need to check access for actions links,
    // we don't have entity to load.
    if (empty($entity)) {
      $route_entity_type_info = $this
        ->getEntityTypeFromRouteMatch($route_match);
      $entity_type_id = $route_entity_type_info['entity_type_id'];
    }
    $entity_type_id = isset($entity_type_id) ? $entity_type_id : $entity
      ->getEntityTypeId();
    $operation = $this
      ->getFormModeOperationName($this->formModeManager
      ->getFormModeMachineName($form_mode_id));
    return AccessResult::allowedIf($this->formModeManager
      ->isActive($entity_type_id, $entity_type_id, $operation))
      ->addCacheTags($cache_tags)
      ->addCacheableDependency($entity);
  }

  /**
   * {@inheritdoc}
   *
   * @return array
   *   The entity object as determined from the passed-in route match.
   */
  public function getEntityTypeFromRouteMatch(RouteMatchInterface $route_match) {
    $route = $route_match
      ->getRouteObject();
    $entity_type_id = $route
      ->getOption('_form_mode_manager_entity_type_id');
    $form_mode = $this->formModeManager
      ->getFormModeMachineName($route
      ->getDefault('_entity_form'));
    $form_mode_definition = $this->formModeManager
      ->getActiveDisplaysByBundle($entity_type_id, $entity_type_id);
    return [
      'entity_type_id' => $entity_type_id,
      'form_mode' => isset($form_mode_definition[$entity_type_id][$form_mode]) ? $form_mode_definition[$entity_type_id][$form_mode] : NULL,
    ];
  }

  /**
   * {@inheritdoc}
   *
   * @return \Drupal\Core\Entity\EntityInterface
   *   The entity loaded form route_match.
   *
   * @throws \Exception
   *   If an invalid entity is retrieving from the route object.
   */
  public function getEntity(RouteMatchInterface $route_match) {

    /** @var \Drupal\Core\Entity\EntityInterface $entity */
    $entity = $this
      ->getEntityFromRouteMatch($route_match);
    if (empty($entity)) {
      $route_entity_type_info = $this
        ->getEntityTypeFromRouteMatch($route_match);

      /** @var \Drupal\Core\Entity\EntityInterface $entity */
      $entity = $this->entityTypeManager
        ->getStorage($route_entity_type_info['entity_type_id'])
        ->create();
    }
    return $entity;
  }

  /**
   * {@inheritdoc}
   *
   * @return \Drupal\Core\Entity\EntityInterface
   *   A new entity object build with given route_match.
   */
  public function getEntityFromRouteMatch(RouteMatchInterface $route_match) {
    $entity_type_id = $route_match
      ->getRouteObject()
      ->getOption('_form_mode_manager_entity_type_id');
    $entity = $route_match
      ->getParameter($entity_type_id);
    return $entity;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AbstractEntityFormModesFactory::$account protected property The current user.
AbstractEntityFormModesFactory::$dateFormatter protected property The date formatter service.
AbstractEntityFormModesFactory::$entityFormBuilder protected property The entity form builder service.
AbstractEntityFormModesFactory::$entityRoutingMap protected property The Routes Manager Plugin.
AbstractEntityFormModesFactory::$entityTypeManager protected property The entity type manager service.
AbstractEntityFormModesFactory::$formBuilder protected property The form builder.
AbstractEntityFormModesFactory::$formModeManager protected property The entity display repository.
AbstractEntityFormModesFactory::$renderer protected property The renderer service.
AbstractEntityFormModesFactory::addPageTitle public function Overrides EntityFormModeManagerInterface::addPageTitle
AbstractEntityFormModesFactory::editPageTitle public function Overrides EntityFormModeManagerInterface::editPageTitle
AbstractEntityFormModesFactory::entityAdd public function Provides the entity add submission form. Overrides EntityFormModeManagerInterface::entityAdd
AbstractEntityFormModesFactory::entityEdit public function Provides the entity 'edit' form. Overrides EntityFormModeManagerInterface::entityEdit
AbstractEntityFormModesFactory::getBundleEntityTypeId public function
AbstractEntityFormModesFactory::getForm public function Gets the built and processed entity form for the given entity.
AbstractEntityFormModesFactory::getFormModeOperationName public function Retrieve the operation (form mode) name in edit context.
AbstractEntityFormModesFactory::getOperation public function Return the correct form mode name for given contexts ($op).
AbstractEntityFormModesFactory::pageTitle public function The _title_callback for the entity.add routes.
AbstractEntityFormModesFactory::__construct public function Constructs a EntityFormModeController object.
SimpleEntityFormModes::addPage public function In simple entities without bundles we don't generate add_page routes. Overrides AbstractEntityFormModesFactory::addPage
SimpleEntityFormModes::checkAccess public function Checks access for the Form Mode Manager routes. Overrides AbstractEntityFormModesFactory::checkAccess
SimpleEntityFormModes::getEntity public function Overrides AbstractEntityFormModesFactory::getEntity
SimpleEntityFormModes::getEntityFromRouteMatch public function Overrides AbstractEntityFormModesFactory::getEntityFromRouteMatch
SimpleEntityFormModes::getEntityTypeFromRouteMatch public function Overrides AbstractEntityFormModesFactory::getEntityTypeFromRouteMatch
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.