getEntityTypeIdKeyType example

        if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) {
          $bundle_entity_type = $this->entityTypeManager->getDefinition($bundle_entity_type_id);

          $route
            // The title callback uses the value of the bundle parameter to             // fetch the respective bundle at runtime.             ->setDefault('bundle_parameter', $bundle_entity_type_id)
            ->setRequirement('_entity_create_access', $entity_type_id . ':{' . $bundle_entity_type_id . '}');

          // Entity types with serial IDs can specify this in their route           // requirements, improving the matching process.           if ($this->getEntityTypeIdKeyType($bundle_entity_type) === 'integer') {
            $route->setRequirement($entity_type_id, '\d+');
          }

          $bundle_entity_parameter = ['type' => 'entity:' . $bundle_entity_type_id];
          if ($bundle_entity_type instanceof ConfigEntityTypeInterface) {
            // The add page might be displayed on an admin path. Even then, we             // need to load configuration overrides so that, for example, the             // bundle label gets translated correctly.             // @see \Drupal\Core\ParamConverter\AdminPathConfigEntityConverter             $bundle_entity_parameter['with_config_overrides'] = TRUE;
          }
          
->setRequirement('_content_moderation_latest_version', 'TRUE')
        ->setOption('_content_moderation_entity_type', $entity_type_id)
        ->setOption('parameters', [
          $entity_type_id => [
            'type' => 'entity:' . $entity_type_id,
            'load_latest_revision' => TRUE,
          ],
        ]);

      // Entity types with serial IDs can specify this in their route       // requirements, improving the matching process.       if ($this->getEntityTypeIdKeyType($entity_type) === 'integer') {
        $route->setRequirement($entity_type_id, '\d+');
      }
      return $route;
    }
  }

  /** * Gets the type of the ID key for a given entity type. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * An entity type. * * @return string|null * The type of the ID key for a given entity type, or NULL if the entity * type does not support fields. */

  public function testGetEntityTypeIdKeyType() {
    $entity_type = $this->prophesize(EntityTypeInterface::class);
    $entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
    $entity_type->id()->willReturn('the_entity_type_id');
    $entity_type->getKey('id')->willReturn('id');

    $field_storage_definition = $this->prophesize(FieldStorageDefinitionInterface::class);
    $field_storage_definition->getType()->willReturn('integer');
    $this->entityFieldManager->getFieldStorageDefinitions('the_entity_type_id')->willReturn(['id' => $field_storage_definition]);

    $type = $this->routeProvider->getEntityTypeIdKeyType($entity_type->reveal());
    $this->assertSame('integer', $type);
  }

  /** * @covers ::getEntityTypeIdKeyType */
  public function testGetEntityTypeIdKeyTypeNotFieldable() {
    $entity_type = $this->prophesize(EntityTypeInterface::class);
    $entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE);
    $this->entityFieldManager->getFieldStorageDefinitions(Argument::any())->shouldNotBeCalled();

    
Home | Imprint | This part of the site doesn't use cookies.