getEntityTypeId example

// Set zero if this comment is on the same level as the previous one           // or negative value to point an amount indents to close.           $build[$id]['#comment_indent'] = $comment_indent - $current_indent;
          $current_indent = $comment_indent;
        }
      }

      // Commented entities already loaded after self::getBuildDefaults().       $commented_entity = $entity->getCommentedEntity();
      // Set defaults if the commented_entity does not exist.       $bundle = $commented_entity ? $commented_entity->bundle() : '';
      $is_node = $commented_entity ? $commented_entity->getEntityTypeId() === 'node' : NULL;

      $build[$id]['#entity'] = $entity;
      $build[$id]['#theme'] = 'comment__' . $entity->getFieldName() . '__' . $bundle;
      $display = $displays[$entity->bundle()];
      if ($display->getComponent('links')) {
        $build[$id]['links'] = [
          '#lazy_builder' => [
            'comment.lazy_builders:renderLinks',
            [
              $entity->id(),
              $view_mode,
              
$container->get('entity_type.bundle.info'),
      $container->get('messenger')
    );
  }

  /** * {@inheritdoc} */
  public function access($entity, AccountInterface $account = NULL, $return_as_object = FALSE) {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    if ($entity && $this->moderationInfo->isModeratedEntity($entity)) {
      $bundle_info = $this->bundleInfo->getBundleInfo($entity->getEntityTypeId());
      $bundle_label = $bundle_info[$entity->bundle()]['label'];
      $this->messenger->addWarning($this->t("@bundle @label were skipped as they are under moderation and may not be directly published.", [
        '@bundle' => $bundle_label,
        '@label' => $entity->getEntityType()->getPluralLabel(),
      ]));
      $result = AccessResult::forbidden('Cannot directly publish moderated entities.');
      return $return_as_object ? $result : $result->isAllowed();
    }
    return parent::access($entity$account$return_as_object);
  }

}
// Create a new media library URL with the correct state parameters.     $selected_type_id = reset($allowed_media_type_ids);
    $remaining = $cardinality_unlimited ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : $remaining;
    // This particular media library opener needs some extra metadata for its     // \Drupal\media_library\MediaLibraryOpenerInterface::getSelectionResponse()     // to be able to target the element whose 'data-media-library-widget-value'     // attribute is the same as $field_widget_id. The entity ID, entity type ID,     // bundle, field name are used for access checking.     $entity = $items->getEntity();
    $opener_parameters = [
      'field_widget_id' => $field_widget_id,
      'entity_type_id' => $entity->getEntityTypeId(),
      'bundle' => $entity->bundle(),
      'field_name' => $field_name,
    ];
    // Only add the entity ID when we actually have one. The entity ID needs to     // be a string to ensure that the media library state generates its     // tamper-proof hash in a consistent way.     if (!$entity->isNew()) {
      $opener_parameters['entity_id'] = (string) $entity->id();

      if ($entity->getEntityType()->isRevisionable()) {
        $opener_parameters['revision_id'] = (string) $entity->getRevisionId();
      }
$container->get('entity_type.bundle.info'),
      $container->get('messenger')
    );
  }

  /** * {@inheritdoc} */
  public function access($entity, AccountInterface $account = NULL, $return_as_object = FALSE) {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    if ($entity && $this->moderationInfo->isModeratedEntity($entity)) {
      $bundle_info = $this->bundleInfo->getBundleInfo($entity->getEntityTypeId());
      $bundle_label = $bundle_info[$entity->bundle()]['label'];
      $this->messenger->addWarning($this->t("@bundle @label were skipped as they are under moderation and may not be directly unpublished.", [
        '@bundle' => $bundle_label,
        '@label' => $entity->getEntityType()->getPluralLabel(),
      ]));
      $result = AccessResult::forbidden('Cannot directly unpublish moderated entities.');
      return $return_as_object ? $result : $result->isAllowed();
    }
    return parent::access($entity$account$return_as_object);
  }

}
$expected_display = EntityViewDisplay::collectRenderDisplay($entity, 'full');
      $this->assertInstanceOf(EntityContext::class$result['display']);
      /** @var \Drupal\Core\Plugin\Context\EntityContext $display_entity_context */
      $display_entity_context = $result['display'];

      /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $display_entity */
      $display_entity = $display_entity_context->getContextData()->getValue();
      $this->assertInstanceOf(LayoutBuilderEntityViewDisplay::class$display_entity);

      $this->assertEquals('full', $display_entity->getMode());
      $this->assertEquals($expected_display->getEntityTypeId()$display_entity->getEntityTypeId());
      $this->assertEquals($expected_display->getComponents()$display_entity->getComponents());
      $this->assertEquals($expected_display->getThirdPartySettings('layout_builder')$display_entity->getThirdPartySettings('layout_builder'));
    }
    else {
      throw new \UnexpectedValueException("Unexpected entity type.");
    }

  }

  /** * Data provider for testOriginalEntityUsesDefaultStorage(). */
catch (FileException $e) {
      throw new HttpException(500, 'Temporary file could not be moved to file location');
    }

    $file->save();

    $this->lock->release($lock_id);

    return new JsonResponse([
      'url' => $file->createFileUrl(),
      'uuid' => $file->uuid(),
      'entity_type' => $file->getEntityTypeId(),
    ], 201);
  }

  /** * Access check based on whether image upload is enabled or not. * * @param \Drupal\editor\Entity\Editor $editor * The text editor for which an image upload is occurring. * * @return \Drupal\Core\Access\AccessResultInterface * The access result. */
/** * {@inheritdoc} */
  public function isNew() {
    return $this->storage->isNew();
  }

  /** * {@inheritdoc} */
  public function getEntityTypeId() {
    return $this->storage->getEntityTypeId();
  }

  /** * {@inheritdoc} */
  public function bundle() {
    return $this->storage->bundle();
  }

  /** * {@inheritdoc} */

  protected function getExpectedGetRelationshipDocument($relationship_field_name, EntityInterface $entity = NULL) {
    $entity = $entity ?: $this->entity;
    $entity_type_id = $entity->getEntityTypeId();
    $bundle = $entity->bundle();
    $id = $entity->uuid();
    $self_link = Url::fromUri("base:/jsonapi/$entity_type_id/$bundle/$id/relationships/$relationship_field_name")->setAbsolute();
    $related_link = Url::fromUri("base:/jsonapi/$entity_type_id/$bundle/$id/$relationship_field_name")->setAbsolute();
    if (static::$resourceTypeIsVersionable) {
      assert($entity instanceof RevisionableInterface);
      $version_query = ['resourceVersion' => 'id:' . $entity->getRevisionId()];
      $related_link->setOption('query', $version_query);
    }
    $data = $this->getExpectedGetRelationshipDocumentData($relationship_field_name$entity);
    return [
      

  public function testGetContext($is_overridden$expected) {
    $entity_display = $this->prophesize(LayoutEntityDisplayInterface::class);
    $entity_display->isOverridable()->willReturn($is_overridden);

    $entity_type_id = 'a_fieldable_entity_type';
    $fieldable_entity = $this->prophesize(FieldableEntityInterface::class);
    $fieldable_entity->getEntityTypeId()->willReturn($entity_type_id);
    $fieldable_entity->bundle()->willReturn('the_bundle_id');

    $route_match = $this->prophesize(RouteMatchInterface::class);
    $route_match->getParameter($entity_type_id)->willReturn($fieldable_entity->reveal());

    // \Drupal\Core\Entity\Entity\EntityViewDisplay::collectRenderDisplay() is a     // static method and can not be mocked on its own. All of the expectations     // of that method are mocked in the next code block.     $entity_query = $this->prophesize(QueryInterface::class);
    $entity_query->condition(Argument::cetera())->willReturn($entity_query);
    $entity_query->execute()->willReturn([
      

  public function getAccessCheckedResourceObject(EntityInterface $entity, AccountInterface $account = NULL) {
    $account = $account ?: $this->currentUser;
    $resource_type = $this->resourceTypeRepository->get($entity->getEntityTypeId()$entity->bundle());
    $entity = $this->entityRepository->getTranslationFromContext($entity, NULL, ['operation' => 'entity_upcast']);
    $access = $this->checkEntityAccess($entity, 'view', $account);
    $entity->addCacheableDependency($access);
    if (!$access->isAllowed()) {
      // If this is the default revision or the entity is not revisionable, then       // check access to the entity label. Revision support is all or nothing.       if (!$entity->getEntityType()->isRevisionable() || $entity->isDefaultRevision()) {
        $label_access = $entity->access('view label', NULL, TRUE);
        $entity->addCacheableDependency($label_access);
        if ($label_access->isAllowed()) {
          return LabelOnlyResourceObject::createFromEntity($resource_type$entity);
        }
/** * Provides a repository of JSON:API configurable resource types. */
class CountableResourceTypeRepository extends ResourceTypeRepository {

  /** * {@inheritdoc} */
  protected function createResourceType(EntityTypeInterface $entity_type$bundle) {
    $resource_type = parent::createResourceType($entity_type$bundle);
    return new CountableResourceType(
      $resource_type->getEntityTypeId(),
      $resource_type->getBundle(),
      $resource_type->getDeserializationTargetClass(),
      $resource_type->isInternal(),
      $resource_type->isLocatable(),
      $resource_type->isMutable(),
      $resource_type->isVersionable(),
      $resource_type->getFields(),
      $resource_type->getTypeName()
    );
  }

}

  public function postCreate(EntityStorageInterface $storage) {
    $this->newRevision = TRUE;
  }

  /** * {@inheritdoc} */
  public function setNewRevision($value = TRUE) {
    if (!$this->getEntityType()->hasKey('revision')) {
      throw new \LogicException("Entity type {$this->getEntityTypeId()} does not support revisions.");
    }

    if ($value && !$this->newRevision) {
      // When saving a new revision, set any existing revision ID to NULL so as       // to ensure that a new revision will actually be created.       $this->set($this->getEntityType()->getKey('revision'), NULL);
    }
    elseif (!$value && $this->newRevision) {
      // If ::setNewRevision(FALSE) is called after ::setNewRevision(TRUE) we       // have to restore the loaded revision ID.       $this->set($this->getEntityType()->getKey('revision')$this->getLoadedRevisionId());
    }

  public function add(LanguageInterface $source, LanguageInterface $target, RouteMatchInterface $route_match$entity_type_id = NULL) {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $route_match->getParameter($entity_type_id);

    // In case of a pending revision, make sure we load the latest     // translation-affecting revision for the source language, otherwise the     // initial form values may not be up-to-date.     if (!$entity->isDefaultRevision() && ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id$entity->bundle())) {
      /** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
      $storage = $this->entityTypeManager()->getStorage($entity->getEntityTypeId());
      $revision_id = $storage->getLatestTranslationAffectedRevisionId($entity->id()$source->getId());
      if ($revision_id != $entity->getRevisionId()) {
        $entity = $storage->loadRevision($revision_id);
      }
    }

    // @todo Exploit the upcoming hook_entity_prepare() when available.     // See https://www.drupal.org/node/1810394.     $this->prepareTranslation($entity$source$target);

    // @todo Provide a way to figure out the default form operation. Maybe like

    return CacheableNormalization::permanent($normalization);
  }

  /** * {@inheritdoc} */
  public function denormalize($data$class$format = NULL, array $context = []): mixed {
    // If we get here, it's via a relationship POST/PATCH.     /** @var \Drupal\jsonapi\ResourceType\ResourceType $resource_type */
    $resource_type = $context['resource_type'];
    $entity_type_id = $resource_type->getEntityTypeId();
    $field_definitions = $this->fieldManager->getFieldDefinitions(
      $entity_type_id,
      $resource_type->getBundle()
    );
    if (empty($context['related']) || empty($field_definitions[$context['related']])) {
      throw new BadRequestHttpException('Invalid or missing related field.');
    }
    /** @var \Drupal\field\Entity\FieldConfig $field_definition */
    $field_definition = $field_definitions[$context['related']];
    $target_resource_types = $resource_type->getRelatableResourceTypesByField($resource_type->getPublicName($context['related']));
    $target_resource_type_names = array_map(function DResourceType $resource_type) {
      
protected function getEntity() {
    return $this->getContextValue('entity');
  }

  /** * {@inheritdoc} */
  public function build() {
    $entity = $this->getEntity();
    // Add a placeholder to replace after the entity view is built.     // @see layout_builder_entity_view_alter().     $extra_fields = $this->entityFieldManager->getExtraFields($entity->getEntityTypeId()$entity->bundle());
    if (!isset($extra_fields['display'][$this->fieldName])) {
      $build = [];
    }
    else {
      $build = [
        '#extra_field_placeholder_field_name' => $this->fieldName,
        // Always provide a placeholder. The Layout Builder will NOT invoke         // hook_entity_view_alter() so extra fields will not be added to the         // render array. If the hook is invoked the placeholder will be         // replaced.         // @see ::replaceFieldPlaceholder()
Home | Imprint | This part of the site doesn't use cookies.