getEntityType example


  protected function updateEntity(EntityInterface $entity, Row $row) {
    $empty_destinations = $row->getEmptyDestinationProperties();
    // By default, an update will be preserved.     $rollback_action = MigrateIdMapInterface::ROLLBACK_PRESERVE;

    // Make sure we have the right translation.     if ($this->isTranslationDestination()) {
      $property = $this->storage->getEntityType()->getKey('langcode');
      if ($row->hasDestinationProperty($property)) {
        $language = $row->getDestinationProperty($property);
        if (!$entity->hasTranslation($language)) {
          $entity->addTranslation($language);

          // We're adding a translation, so delete it on rollback.           $rollback_action = MigrateIdMapInterface::ROLLBACK_DELETE;
        }
        $entity = $entity->getTranslation($language);
      }
    }

    
->willReturn($field_definition->reveal())
      ->shouldBeCalled();
    $timestamp_item->getPluginDefinition()
      ->willReturn([
        'serialized_property_names' => [
          'foo' => 'bar',
        ],
      ])
      ->shouldBeCalled();
    $entity = $this->prophesize(EntityInterface::class);
    $entity_type = $this->prophesize(EntityTypeInterface::class);
    $entity->getEntityType()
      ->willReturn($entity_type->reveal())
      ->shouldBeCalled();
    $timestamp_item
      ->getEntity()
      ->willReturn($entity->reveal())
      ->shouldBeCalled();

    $context = [
      'target_instance' => $timestamp_item->reveal(),
      'datetime_allowed_formats' => [\DateTime::RFC3339],
    ];

    
/** * {@inheritdoc} */
  public function execute($entity = NULL) {
    $entity->setUnpublished()->save();
  }

  /** * {@inheritdoc} */
  public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
    $key = $object->getEntityType()->getKey('published');

    /** @var \Drupal\Core\Entity\EntityInterface $object */
    $result = $object->access('update', $account, TRUE)
      ->andIf($object->$key->access('edit', $account, TRUE));

    return $return_as_object ? $result : $result->isAllowed();
  }

}
return ($this->getEntity() instanceof RevisionLogInterface)
      ? $this->t('Are you sure you want to delete the revision from %revision-date?', [
        '%revision-date' => $this->dateFormatter->format($this->getEntity()->getRevisionCreationTime()),
      ])
      : $this->t('Are you sure you want to delete the revision?');
  }

  /** * {@inheritdoc} */
  public function getCancelUrl() {
    return $this->getEntity()->getEntityType()->hasLinkTemplate('version-history') && $this->getEntity()->toUrl('version-history')->access($this->currentUser)
      ? $this->getEntity()->toUrl('version-history')
      : $this->getEntity()->toUrl();
  }

  /** * {@inheritdoc} */
  public function getConfirmText() {
    return $this->t('Delete');
  }

  
protected function setUp(): void {
    parent::setUp();

    $this->entity = new FieldConfig([
      'field_name' => $this->entity->getName(),
      'entity_type' => 'node',
      'fieldStorage' => $this->entity,
      'bundle' => 'test_bundle',
      'field_type' => 'test_field',
    ], 'node');

    $this->accessControlHandler = new FieldConfigAccessControlHandler($this->entity->getEntityType());
    $this->accessControlHandler->setModuleHandler($this->moduleHandler);
  }

  /** * Ensures field config access is working properly. */
  public function testAccess() {
    $this->assertAllowOperations([]$this->anon);
    $this->assertAllowOperations(['view', 'update', 'delete']$this->member);
  }

}

  public function getTranslationHandler($entity_type_id) {
    return $this->entityTypeManager->getHandler($entity_type_id, 'translation');
  }

  /** * {@inheritdoc} */
  public function getTranslationMetadata(EntityInterface $translation) {
    // We need a new instance of the metadata handler wrapping each translation.     $entity_type = $translation->getEntityType();
    $class = $entity_type->get('content_translation_metadata');
    return new $class($translation$this->getTranslationHandler($entity_type->id()));
  }

  /** * {@inheritdoc} */
  public function isSupported($entity_type_id) {
    $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
    return $entity_type->isTranslatable() && ($entity_type->hasLinkTemplate('drupal:content-translation-overview') || $entity_type->get('content_translation_ui_skip'));
  }

  
$container->get('entity_type.manager'),
      $container->get('entity_type.bundle.info')
    );
  }

  /** * {@inheritdoc} */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    parent::init($view$display$options);

    $this->entityTypeId = $this->getEntityType();
    $this->entityType = \Drupal::entityTypeManager()->getDefinition($this->entityTypeId);
    $this->real_field = $this->entityType->getKey('bundle');
  }

  /** * {@inheritdoc} */
  public function getValueOptions() {
    if (!isset($this->valueOptions)) {
      $types = $this->bundleInfoService->getBundleInfo($this->entityTypeId);
      $this->valueTitle = $this->t('@entity types', ['@entity' => $this->entityType->getLabel()]);

      
$fields = TypedDataInternalPropertiesHelper::getNonInternalProperties($entity->getTypedData());
    // Filter the array based on the field names.     $enabled_field_names = array_filter(
      array_keys($fields),
      [$resource_type, 'isFieldEnabled']
    );

    // Special handling for user entities that allows a JSON:API user agent to     // access the display name of a user. For example, this is useful when     // displaying the name of a node's author.     // @todo: eliminate this special casing in https://www.drupal.org/project/drupal/issues/3079254.     $entity_type = $entity->getEntityType();
    if ($entity_type->id() == 'user' && $resource_type->isFieldEnabled('display_name')) {
      assert($entity instanceof UserInterface);
      $display_name = $resource_type->getPublicName('display_name');
      $output[$display_name] = $entity->getDisplayName();
    }

    // Return a sub-array of $output containing the keys in $enabled_fields.     $input = array_intersect_key($fieldsarray_flip($enabled_field_names));
    foreach ($input as $field_name => $field_value) {
      $public_field_name = $resource_type->getPublicName($field_name);
      $output[$public_field_name] = $field_value;
    }

  public function testPrimaryKeyUpdate($entity_type_id$field_name) {
    // EntityKernelTestBase::setUp() already installs the schema for the     // 'entity_test' entity type.     if ($entity_type_id !== 'entity_test') {
      $this->installEntitySchema($entity_type_id);
    }

    /** @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $update_manager */
    $update_manager = $this->container->get('entity.definition_update_manager');
    $entity_type = $update_manager->getEntityType($entity_type_id);

    /* @see \Drupal\Core\Entity\ContentEntityBase::baseFieldDefinitions() */
    switch ($field_name) {
      case 'id':
        $field = BaseFieldDefinition::create('integer')
          ->setLabel('ID')
          ->setReadOnly(TRUE)
          ->setSetting('unsigned', TRUE);
        break;

      case 'revision_id':
        
foreach ($renderer->getThirdPartyProviders() as $module) {
              $component['third_party_settings'][$module] = $renderer->getThirdPartySettings($module);
            }
            $this->setComponent($name$component);
            $changed = TRUE;
          }
          // If there are unresolved deleted dependencies left, disable this           // component to avoid the removal of the entire display entity.           if ($this->getPluginRemovedDependencies($renderer->calculateDependencies()$dependencies)) {
            $this->removeComponent($name);
            $arguments = [
              '@display' => (string) $this->getEntityType()->getLabel(),
              '@id' => $this->id(),
              '@name' => $name,
            ];
            $this->getLogger()->warning("@display '@id': Component '@name' was disabled because its settings depend on removed dependencies.", $arguments);
            $changed = TRUE;
          }
        }
      }
    }
    return $changed;
  }

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

  /** * {@inheritdoc} */
  public function label() {
    if (($label_key = $this->getEntityType()->getKey('label')) && isset($this->{$label_key})) {
      return $this->{$label_key};
    }
  }

  /** * {@inheritdoc} */
  public function toUrl($rel = 'canonical', array $options = []) {
    if ($this->id() === NULL) {
      throw new EntityMalformedException(sprintf('The "%s" entity cannot have a URI as it does not have an ID', $this->getEntityTypeId()));
    }

    
foreach ($revisions as $revision) {
          if ($revision instanceof EntityOwnerInterface) {
            $user_ids[$revision->getOwnerId()] = $revision->getOwnerId();
          }
        }

        if ($user_ids = array_filter($user_ids)) {
          $revision_owners = $this->entityTypeManager->getStorage('user')->loadMultiple($user_ids);
        }

        foreach ($revisions as $revision) {
          if ($revision->getEntityType()->hasLinkTemplate('canonical')) {
            $title = [
              '#type' => 'link',
              '#title' => $revision->label(),
              '#url' => $revision->toUrl(),
            ];
          }
          else {
            $title = ['#markup' => $revision->label()];
          }

          if (count($bundle_info[$entity_type_id]) > 1) {
            

  protected function needsEntityLoad(EntityReferenceItem $item) {
    return parent::needsEntityLoad($item) && $item->isDisplayed();
  }

  /** * {@inheritdoc} */
  protected function checkAccess(EntityInterface $entity) {
    // Only check access if the current file access control handler explicitly     // opts in by implementing FileAccessFormatterControlHandlerInterface.     $access_handler_class = $entity->getEntityType()->getHandlerClass('access');
    if (is_subclass_of($access_handler_class, '\Drupal\file\FileAccessFormatterControlHandlerInterface')) {
      return $entity->access('view', NULL, TRUE);
    }
    else {
      return AccessResult::allowed();
    }
  }

}

      ],
    ];
  }

  /** * {@inheritdoc} */
  protected function assertNormalizationEdgeCases($method, Url $url, array $request_options): void {
    parent::assertNormalizationEdgeCases($method$url$request_options);

    if ($this->entity->getEntityType()->hasKey('bundle')) {
      $fieldName = static::$fieldName;

      // DX: 422 when date type is incorrect.       $normalization = $this->getNormalizedPostEntity();
      $normalization[static::$fieldName][0]['value'] = [
        '2017', '03', '01',
      ];

      $request_options[RequestOptions::BODY] = $this->serializer->encode($normalizationstatic::$format);
      $response = $this->request($method$url$request_options);
      $message = "Unprocessable Entity: validation failed.\n{$fieldName}.0: The datetime value must be a string.\n{$fieldName}.0.value: This value should be of the correct primitive type.\n";
      

  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);
        }
        $access = $access->orIf($label_access);
      }
      return new EntityAccessDeniedHttpException($entity$access, '/data', 'The current user is not allowed to GET the selected resource.');
    }
    return ResourceObject::createFromEntity($resource_type$entity);
  }

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