You are here

class RouteEnhancer in Automatic Entity Label 8

Same name and namespace in other branches
  1. 8.3 src/Routing/RouteEnhancer.php \Drupal\auto_entitylabel\Routing\RouteEnhancer
  2. 8.2 src/Routing/RouteEnhancer.php \Drupal\auto_entitylabel\Routing\RouteEnhancer

Route Enhancer class.

Enhances Auto Entity Label routes by adding proper information about the bundle name.

Hierarchy

Expanded class hierarchy of RouteEnhancer

1 string reference to 'RouteEnhancer'
auto_entitylabel.services.yml in ./auto_entitylabel.services.yml
auto_entitylabel.services.yml
1 service uses RouteEnhancer
auto_entitylabel.route_enhancer in ./auto_entitylabel.services.yml
Drupal\auto_entitylabel\Routing\RouteEnhancer

File

src/Routing/RouteEnhancer.php, line 16

Namespace

Drupal\auto_entitylabel\Routing
View source
class RouteEnhancer implements RouteEnhancerInterface {

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

  /**
   * Constructs a RouteEnhancer object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager) {
    $this->entityManager = $entity_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function enhance(array $defaults, Request $request) {
    if (($bundle = $this->entityManager
      ->getDefinition($defaults['entity_type_id'])
      ->getBundleEntityType()) && isset($defaults[$bundle])) {

      // Auto Entity Label forms only need the actual name of the bundle they're
      // dealing with, not an upcasted entity object, so provide a simple way
      // for them to get it.
      $defaults['bundle'] = $defaults['_raw_variables']
        ->get($bundle);
    }
    return $defaults;
  }

  /**
   * {@inheritdoc}
   */
  public function applies(Route $route) {
    return $route
      ->hasOption('auto_label');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteEnhancer::$entityManager protected property The entity manager.
RouteEnhancer::applies public function Declares if the route enhancer applies to the given route. Overrides RouteEnhancerInterface::applies
RouteEnhancer::enhance public function Update the defaults based on its own data and the request.
RouteEnhancer::__construct public function Constructs a RouteEnhancer object.