You are here

EntityHierarchyHandler.php in Entity Reference Hierarchy 3.x

Same filename and directory in other branches
  1. 8.2 src/Handler/EntityHierarchyHandler.php

File

src/Handler/EntityHierarchyHandler.php
View source
<?php

namespace Drupal\entity_hierarchy\Handler;

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Url;

/**
 * Defines a class for provide entity-type specific entity hierarchy logic.
 */
class EntityHierarchyHandler implements EntityHierarchyHandlerInterface {

  /**
   * {@inheritdoc}
   */
  public function getAddChildUrl(EntityTypeInterface $entityType, ContentEntityInterface $parent, $bundle, $fieldName) {
    $routeName = "entity.{$entityType->id()}.add_form";
    return Url::fromRoute($routeName, [
      $entityType
        ->getKey('bundle') => $bundle,
    ], [
      'query' => [
        $fieldName => $parent
          ->id(),
      ],
    ]);
  }

}

Classes

Namesort descending Description
EntityHierarchyHandler Defines a class for provide entity-type specific entity hierarchy logic.