getUriCallback example

$route_name = "entity.{$this->entityTypeId}." . str_replace(['-', 'drupal:']['_', '']$rel);
      $uri = new Url($route_name$route_parameters);
    }
    else {
      $bundle = $this->bundle();
      // A bundle-specific callback takes precedence over the generic one for       // the entity type.       $bundles = $this->entityTypeBundleInfo()->getBundleInfo($this->getEntityTypeId());
      if (isset($bundles[$bundle]['uri_callback'])) {
        $uri_callback = $bundles[$bundle]['uri_callback'];
      }
      elseif ($entity_uri_callback = $this->getEntityType()->getUriCallback()) {
        $uri_callback = $entity_uri_callback;
      }

      // Invoke the callback to get the URI. If there is no callback, use the       // default URI format.       if (isset($uri_callback) && is_callable($uri_callback)) {
        $uri = call_user_func($uri_callback$this);
      }
      else {
        throw new UndefinedLinkTemplateException("No link template '$rel' found for the '{$this->getEntityTypeId()}' entity type");
      }
    }

  public function testToUrlUriCallbackUndefined(array $bundle_info$uri_callback) {
    $entity = $this->getEntity(UrlTestEntity::class['id' => $this->entityId]);

    $this->registerBundleInfo($bundle_info);
    $this->entityType->getUriCallback()->willReturn($uri_callback);

    $link_template = 'canonical';
    $this->expectException(UndefinedLinkTemplateException::class);
    $this->expectExceptionMessage("No link template '$link_template' found for the '$this->entityTypeId' entity type");
    $entity->toUrl($link_template);
  }

  /** * Provides data for testToUrlUriCallbackUndefined(). * * @return array * An array of test cases for testToUrlUriCallbackUndefined(). */
Home | Imprint | This part of the site doesn't use cookies.