getHandlerClass example


  public function getAccessControlHandler($entity_type_id) {
    return $this->getHandler($entity_type_id, 'access');
  }

  /** * {@inheritdoc} */
  public function getHandler($entity_type_id$handler_type) {
    if (!isset($this->handlers[$handler_type][$entity_type_id])) {
      $definition = $this->getDefinition($entity_type_id);
      $class = $definition->getHandlerClass($handler_type);
      if (!$class) {
        throw new InvalidPluginDefinitionException($entity_type_idsprintf('The "%s" entity type did not specify a %s handler.', $entity_type_id$handler_type));
      }
      $this->handlers[$handler_type][$entity_type_id] = $this->createHandlerInstance($class$definition);
    }

    return $this->handlers[$handler_type][$entity_type_id];
  }

  /** * {@inheritdoc} */

  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();
    }
  }

}

  public function testGetHandler() {
    $controller = $this->getTestHandlerClass();
    $entity_type = $this->setUpEntityType([
      'handlers' => [
        'storage' => $controller,
        'form' => [
          'default' => $controller,
        ],
      ],
    ]);
    $this->assertSame($controller$entity_type->getHandlerClass('storage'));
    $this->assertSame($controller$entity_type->getHandlerClass('form', 'default'));
    $this->assertNull($entity_type->getHandlerClass('foo'));
    $this->assertNull($entity_type->getHandlerClass('foo', 'bar'));
  }

  /** * Tests the getStorageClass() method. */
  public function testGetStorageClass() {
    $controller = $this->getTestHandlerClass();
    $entity_type = $this->setUpEntityType([
      


  /** * Tests translatable fields storage/retrieval. */
  public function testTranslatableFieldSaveLoad() {
    /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
    $entity_type = $this->container->get('entity_type.manager')->getDefinition('media');
    $this->assertTrue($entity_type->isTranslatable(), 'Media is translatable.');

    // Check if the translation handler uses the content_translation handler.     $translation_handler_class = $entity_type->getHandlerClass('translation');
    $this->assertEquals(ContentTranslationHandler::class$translation_handler_class, 'Translation handler is set to use the content_translation handler.');

    // Prepare the field translations.     $source_field_definition = $this->testTranslationMediaType->getSource()->getSourceFieldDefinition($this->testTranslationMediaType);
    $source_field_storage = $source_field_definition->getFieldStorageDefinition();
    /** @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage $media_storage */
    $media_storage = $this->container->get('entity_type.manager')->getStorage('media');
    /** @var \Drupal\media\Entity\Media $media */
    $media = $media_storage->create([
      'bundle' => $this->testTranslationMediaType->id(),
      'name' => 'Unnamed',
    ]);

  }

  /** * Tests the getStorage() method. * * @covers ::getStorage */
  public function testGetStorage() {
    $class = $this->getTestHandlerClass();
    $entity = $this->prophesize(EntityTypeInterface::class);
    $entity->getHandlerClass('storage')->willReturn($class);
    $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]);

    $this->assertInstanceOf($class$this->entityTypeManager->getStorage('test_entity_type'));
  }

  /** * Tests the getListBuilder() method. * * @covers ::getListBuilder */
  public function testGetListBuilder() {
    
return $this->revisionDataTable;
  }

  /** * Gets the entity type's storage schema object. * * @return \Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema * The schema object. */
  protected function getStorageSchema() {
    if (!isset($this->storageSchema)) {
      $class = $this->entityType->getHandlerClass('storage_schema') ?: 'Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema';
      $this->storageSchema = new $class($this->entityTypeManager, $this->entityType, $this$this->database, $this->entityFieldManager);
    }
    return $this->storageSchema;
  }

  /** * Updates the wrapped entity type definition. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The update entity type. * * @internal Only to be used internally by Entity API. Expected to be * removed by https://www.drupal.org/node/2274017. */
$handler = $handlers[$handler_type];
    if ($nested) {
      $handler = $handler[$nested];
    }
    return class_exists($handler);
  }

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

  /** * {@inheritdoc} */
  public function setStorageClass($class) {
    $this->checkStorageClass($class);
    $this->handlers['storage'] = $class;
    return $this;
  }

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