entityClassImplements example

/** * Wraps _comment_entity_uses_integer_id(). * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * Entity type being tested. * * @return bool * TRUE if entity-type uses integer IDs. */
  protected function entityTypeSupportsComments(EntityTypeInterface $entity_type) {
    return $entity_type->entityClassImplements(FieldableEntityInterface::class) && _comment_entity_uses_integer_id($entity_type->id());
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $comment_type = $this->entity;
    $status = $comment_type->save();

    $edit_link = $this->entity->toLink($this->t('Edit'), 'edit-form')->toString();
    if ($status == SAVED_UPDATED) {
      
$fields[$revision_id_field_name] = new ResourceTypeAttribute($revision_id_field_name, "drupal_internal__$revision_id_field_name");
    }
    if ($entity_type instanceof ConfigEntityTypeInterface) {
      // The '_core' key is reserved by Drupal core to handle complex edge cases       // correctly. Data in the '_core' key is irrelevant to clients reading       // configuration, and is not allowed to be set by clients writing       // configuration: it is for Drupal core only, and managed by Drupal core.       // @see https://www.drupal.org/node/2653358       $fields['_core'] = new ResourceTypeAttribute('_core', NULL, FALSE);
    }

    $is_fieldable = $entity_type->entityClassImplements(FieldableEntityInterface::class);
    if ($is_fieldable) {
      $field_definitions = $this->entityFieldManager->getFieldDefinitions($entity_type->id()$bundle);
    }

    // For all other fields, use their internal field name also as their public     // field name. Unless they're called "id" or "type": those names are     // reserved by the JSON:API spec.     // @see http://jsonapi.org/format/#document-resource-object-fields     $reserved_field_names = ['id', 'type'];
    foreach (array_diff($field_namesarray_keys($fields)) as $field_name) {
      $alias = $field_name;
      

  protected function resourceTypesAreTraversable(array $resource_types) {
    foreach ($resource_types as $resource_type) {
      $entity_type_definition = $this->entityTypeManager->getDefinition($resource_type->getEntityTypeId());
      if ($entity_type_definition->entityClassImplements(FieldableEntityInterface::class)) {
        return TRUE;
      }
    }
    return FALSE;
  }

  /** * Gets all unique reference property names from the given field definitions. * * @param \Drupal\Core\TypedData\ComplexDataDefinitionInterface[] $candidate_definitions * A list of targeted field item definitions specified by the path. * * @return string[] * The reference property names, if any. */
$route->setPath('/the/add/form/link/template/{the_bundle_key}');
    $route
      ->setDefault('_title_callback', 'Drupal\Core\Entity\Controller\EntityController::addBundleTitle')
      ->setDefault('bundle_parameter', 'the_bundle_key')
      ->setRequirement('_entity_create_access', 'the_entity_type_id:{the_bundle_key}');
    $data['add_form_bundle_static'] = [clone $route$entity_type4->reveal()];

    $entity_type5 = static::getEntityType($entity_type4);
    $entity_type5->getBundleEntityType()->willReturn('the_bundle_entity_type_id');
    $entity_type5->getLinkTemplate('add-form')->willReturn('/the/add/form/link/template/{the_bundle_entity_type_id}');
    $bundle_entity_type = static::getEntityType();
    $bundle_entity_type->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE);
    $route->setPath('/the/add/form/link/template/{the_bundle_entity_type_id}');
    $route
      ->setDefault('bundle_parameter', 'the_bundle_entity_type_id')
      ->setRequirement('_entity_create_access', 'the_entity_type_id:{the_bundle_entity_type_id}')
      ->setOption('parameters', [
        'the_bundle_entity_type_id' => [
          'type' => 'entity:the_bundle_entity_type_id',
        ],
      ]);
    $data['add_form_bundle_entity_id_key_type_null'] = [clone $route$entity_type5->reveal()$bundle_entity_type->reveal()];

    
/** * Checks whether the entity type supports author natively. * * @return bool * TRUE if metadata is natively supported, FALSE otherwise. */
  protected function hasAuthor() {
    // Check for field named uid, but only in case the entity implements the     // EntityOwnerInterface. This helps to exclude cases, where the uid is     // defined as field name, but is not meant to be an owner field; for     // instance, the User entity.     return $this->entityType->entityClassImplements(EntityOwnerInterface::class) && $this->checkFieldStorageDefinitionTranslatability('uid');
  }

  /** * Checks whether the entity type supports published status natively. * * @return bool * TRUE if metadata is natively supported, FALSE otherwise. */
  protected function hasPublishedStatus() {
    return $this->checkFieldStorageDefinitionTranslatability('status');
  }

  

  protected function getContentEntityPaths() {
    if (!isset($this->contentEntityPaths)) {
      $this->contentEntityPaths = [];
      $entity_types = $this->entityTypeManager->getDefinitions();
      foreach ($entity_types as $entity_type_id => $entity_type) {
        if ($entity_type->entityClassImplements(ContentEntityInterface::class)) {
          $entity_paths = array_fill_keys($entity_type->getLinkTemplates()$entity_type_id);
          $this->contentEntityPaths = array_merge($this->contentEntityPaths, $entity_paths);
        }
      }
    }

    return $this->contentEntityPaths;
  }

}
return $field_storage_definitions[$entity_type->getKey('id')]->getType() === 'integer';
  }

  /** * Returns an array of relevant entity types. * * @return \Drupal\Core\Entity\EntityTypeInterface[] * An array of entity types. */
  protected function getEntityTypes() {
    return array_filter($this->entityTypeManager->getDefinitions()function DEntityTypeInterface $entity_type) {
      return $entity_type->entityClassImplements(FieldableEntityInterface::class) && $entity_type->hasHandlerClass('form', 'layout_builder') && $entity_type->hasViewBuilderClass() && $entity_type->hasLinkTemplate('canonical');
    });
  }

  /** * {@inheritdoc} */
  public function getDefaultSectionStorage() {
    $display = LayoutBuilderEntityViewDisplay::collectRenderDisplay($this->getEntity()$this->getContextValue('view_mode'));
    return $this->sectionStorageManager->load('defaults', ['display' => EntityContext::fromEntity($display)]);
  }

  

  protected $initialized = FALSE;

  /** * {@inheritdoc} */
  public function __construct(array $values$entity_type) {
    if (!isset($values['targetEntityType']) || !isset($values['bundle'])) {
      throw new \InvalidArgumentException('Missing required properties for an EntityDisplay entity.');
    }

    if (!$this->entityTypeManager()->getDefinition($values['targetEntityType'])->entityClassImplements(FieldableEntityInterface::class)) {
      throw new \InvalidArgumentException('EntityDisplay entities can only handle fieldable entity types.');
    }

    $this->renderer = \Drupal::service('renderer');

    // A plugin manager and a context type needs to be set by extending classes.     if (!isset($this->pluginManager)) {
      throw new \RuntimeException('Missing plugin manager.');
    }
    if (!isset($this->displayContext)) {
      throw new \RuntimeException('Missing display context type.');
    }
return AccessResult::forbidden("$key parameter is missing.")->addCacheableDependency($state);
      }
    }

    $entity_type_id = $parameters['entity_type_id'];
    $bundle = $parameters['bundle'];
    $field_name = $parameters['field_name'];

    // Since we defer to a field to determine access, ensure we are dealing with     // a fieldable entity type.     $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
    if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) {
      throw new \LogicException("The media library can only be opened by fieldable entities.");
    }

    $storage = $this->entityTypeManager->getStorage($entity_type_id);
    $access_handler = $this->entityTypeManager->getAccessControlHandler($entity_type_id);

    if (!empty($parameters['revision_id'])) {
      $entity = $storage->loadRevision($parameters['revision_id']);
      $entity_access = $access_handler->access($entity, 'update', $account, TRUE);
    }
    elseif ($parameters['entity_id']) {
      
    $storage->getEntityClass(NULL)->willReturn(EntityTypeManagerTestEntity::class);
    $storage->getEntityClass(Argument::type('string'))->willReturn(EntityTypeManagerTestEntity::class);
    // When using the "test_entity_bundle_class" bundle, return the     // EntityTypeManagerTestEntityBundle class     $storage->getEntityClass('test_entity_bundle_class')->willReturn(EntityTypeManagerTestEntityBundle::class);

    $this->entityTypeManager->getStorage('test_entity_type')->willReturn($storage->reveal());
    $this->entityTypeManager->getStorage('base_field_override')->willReturn($storage->reveal());

    $this->entityType->getClass()->willReturn($entity_class);
    $this->entityType->getKeys()->willReturn($entity_keys + ['default_langcode' => 'default_langcode']);
    $this->entityType->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
    $this->entityType->isTranslatable()->willReturn(FALSE);
    $this->entityType->isRevisionable()->willReturn(FALSE);
    $this->entityType->getProvider()->willReturn('the_provider');
    $this->entityType->id()->willReturn('the_entity_id');

    return $field_definition->reveal();
  }

  /** * Tests the clearCachedFieldDefinitions() method. * * @covers ::clearCachedFieldDefinitions */
$this->negotiatorIds = $negotiator_ids;
  }

  /** * {@inheritdoc} */
  public function isEntityTypeSupported(EntityTypeInterface $entity_type) {
    $entity_type_id = $entity_type->id();
    if (!isset($this->supported[$entity_type_id])) {
      // Only entity types which are revisionable and publishable can belong       // to a workspace.       $this->supported[$entity_type_id] = $entity_type->entityClassImplements(EntityPublishedInterface::class) && $entity_type->isRevisionable();
    }
    return $this->supported[$entity_type_id];
  }

  /** * {@inheritdoc} */
  public function getSupportedEntityTypes() {
    $entity_types = [];
    foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      if ($this->isEntityTypeSupported($entity_type)) {
        

  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    // Also keep the 'entity' defined as is.     $this->derivatives[''] = $base_plugin_definition;
    // Add definitions for each entity type and bundle.     foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      $class = $entity_type->entityClassImplements(ConfigEntityInterface::class) ? ConfigEntityAdapter::class D EntityAdapter::class;
      $this->derivatives[$entity_type_id] = [
        'class' => $class,
        'label' => $entity_type->getLabel(),
        'constraints' => $entity_type->getConstraints(),
        'internal' => $entity_type->isInternal(),
      ] + $base_plugin_definition;

      // Incorporate the bundles as entity:$entity_type:$bundle, if any.       $bundle_info = $this->bundleInfoService->getBundleInfo($entity_type_id);
      if (count($bundle_info) > 1 || $entity_type->getKey('bundle')) {
        foreach ($bundle_info as $bundle => $info) {
          

  protected function doCount() {
    return $this->query()->count()->execute();
  }

  /** * {@inheritdoc} */
  public function fields() {
    // Retrieving fields from a non-fieldable content entity will throw a     // LogicException. Return an empty list of fields instead.     if (!$this->entityType->entityClassImplements('Drupal\Core\Entity\FieldableEntityInterface')) {
      return [];
    }
    $field_definitions = $this->entityFieldManager->getBaseFieldDefinitions($this->entityType->id());
    if (!empty($this->configuration['bundle'])) {
      $field_definitions += $this->entityFieldManager->getFieldDefinitions($this->entityType->id()$this->configuration['bundle']);
    }
    $fields = array_map(function D$definition) {
      return (string) $definition->getLabel();
    }$field_definitions);
    return $fields;
  }

  

  protected function loadBundleDescriptions(array $bundles, EntityTypeInterface $bundle_entity_type) {
    if (!$bundle_entity_type->entityClassImplements(EntityDescriptionInterface::class)) {
      return $bundles;
    }
    $bundle_names = array_keys($bundles);
    $storage = $this->entityTypeManager->getStorage($bundle_entity_type->id());
    /** @var \Drupal\Core\Entity\EntityDescriptionInterface[] $bundle_entities */
    $bundle_entities = $storage->loadMultiple($bundle_names);
    foreach ($bundles as $bundle_name => &$bundle_info) {
      if (isset($bundle_entities[$bundle_name])) {
        $bundle_info['description'] = $bundle_entities[$bundle_name]->getDescription();
      }
    }

    

  }

  /** * Returns an array of relevant entity types. * * @return \Drupal\Core\Entity\EntityTypeInterface[] * An array of entity types. */
  protected function getEntityTypes() {
    return array_filter($this->entityTypeManager->getDefinitions()function DEntityTypeInterface $entity_type) {
      return $entity_type->entityClassImplements(FieldableEntityInterface::class) && $entity_type->hasHandlerClass('form', 'layout_builder') && $entity_type->hasViewBuilderClass() && $entity_type->get('field_ui_base_route');
    });
  }

  /** * {@inheritdoc} */
  public function getContextsDuringPreview() {
    $contexts = parent::getContextsDuringPreview();

    // During preview add a sample entity for the target entity type and bundle.     $display = $this->getDisplay();
    
Home | Imprint | This part of the site doesn't use cookies.