/**
  * {@inheritdoc}
  */
 public function enhance(Description $description)
 {
     $metadata = $this->registry->getByClass($description->getResource()->getPayloadType());
     $payload = $description->getResource()->getPayload();
     // the request configuration provides the route names.
     $request = $this->requestStack->getCurrentRequest();
     $configuration = $this->requestConfigurationFactory->create($metadata, $request);
     $map = [Descriptor::LINK_SHOW_HTML => 'show', Descriptor::LINK_LIST_HTML => 'index', Descriptor::LINK_EDIT_HTML => 'update', Descriptor::LINK_CREATE_HTML => 'create', Descriptor::LINK_REMOVE_HTML => 'delete'];
     foreach ($map as $descriptor => $action) {
         // note that some resources may not have routes
         // registered with sonata (f.e. folder resources)
         // so we ignore route-not-found exceptions.
         try {
             $url = $this->urlGenerator->generate($configuration->getRouteName($action), ['id' => $payload->getId()]);
             $description->set($descriptor, $url);
         } catch (RouteNotFoundException $e) {
         }
     }
     // if a previous enhancer has set the children types descriptor, then
     // we can generate the LINKS_CREATE_CHILD_HTML descriptor.
     if ($description->has(Descriptor::CHILDREN_TYPES)) {
         $this->processChildrenTypes($description, $metadata, $request, $payload);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function enhance(Description $description)
 {
     $metadata = $this->metadataFactory->getMetadataFor($description->getResource()->getPayloadType());
     $childClasses = $metadata->getChildClasses();
     $childTypes = [];
     // explode the allowed types into concrete classes
     foreach ($this->metadataFactory->getAllMetadata() as $childMetadata) {
         foreach ($childClasses as $childClass) {
             if ($childClass == $childMetadata->name || $childMetadata->getReflectionClass()->isSubclassOf($childClass)) {
                 $childTypes[] = $childMetadata->name;
             }
         }
     }
     $description->set(Descriptor::CHILDREN_ALLOW, !$metadata->isLeaf());
     $description->set(Descriptor::CHILDREN_TYPES, $childTypes);
 }
 /**
  * {@inheritdoc}
  */
 public function enhance(Description $description)
 {
     $object = $description->getResource()->getPayload();
     // sonata has dependency on ClassUtils so this is fine.
     $class = ClassUtils::getClass($object);
     $admin = $this->pool->getAdminByClass($class);
     $links = array();
     $routeCollection = $admin->getRoutes();
     foreach ($routeCollection->getElements() as $code => $route) {
         $routeName = $route->getDefault('_sonata_name');
         $url = $this->urlGenerator->generate($routeName, array($admin->getIdParameter() => $admin->getUrlsafeIdentifier($object)), true);
         $routeRole = substr($code, strlen($admin->getCode()) + 1);
         $links[$routeRole] = $url;
     }
     if (isset($links['list'])) {
         $description->set('list', $links['list']);
         unset($links['list']);
     }
     if (isset($links['create'])) {
         $description->set(Descriptor::LINK_CREATE_HTML, $links['create']);
         unset($links['create']);
     }
     if (isset($links['edit'])) {
         $description->set(Descriptor::LINK_EDIT_HTML, $links['edit']);
         unset($links['edit']);
     }
     if (isset($links['delete'])) {
         $description->set(Descriptor::LINK_REMOVE_HTML, $links['delete']);
         unset($links['delete']);
     }
     if (isset($links['show'])) {
         $description->set(Descriptor::LINK_SHOW_HTML, $links['show']);
         unset($links['show']);
     }
     $description->set(Descriptor::PAYLOAD_TITLE, $admin->toString($object));
     $description->set(Descriptor::TYPE_ALIAS, $admin->getLabel());
 }
 /**
  * It should return the resource that it describes.
  */
 public function testGetResource()
 {
     $resource = $this->description->getResource();
     $this->assertSame($this->resource->reveal(), $resource);
 }