hasHandlerClass example


  public function isModeratedEntityType(EntityTypeInterface $entity_type) {
    $bundles = $this->bundleInfo->getBundleInfo($entity_type->id());
    return !empty(array_column($bundles, 'workflow'));
  }

  /** * {@inheritdoc} */
  public function canModerateEntitiesOfEntityType(EntityTypeInterface $entity_type) {
    return $entity_type->hasHandlerClass('moderation');
  }

  /** * {@inheritdoc} */
  public function shouldModerateEntitiesOfBundle(EntityTypeInterface $entity_type$bundle) {
    if ($this->canModerateEntitiesOfEntityType($entity_type)) {
      $bundles = $this->bundleInfo->getBundleInfo($entity_type->id());
      return isset($bundles[$bundle]['workflow']);
    }
    return FALSE;
  }
'handler_settings' => [
          'target_bundles' => [
            $referenced_entity->bundle() => $referenced_entity->bundle(),
          ],
          'sort' => ['field' => '_none'],
          'auto_create' => FALSE,
        ],
      ],
    ])->save();
    /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
    $display_repository = \Drupal::service('entity_display.repository');
    if (!$this->entity->getEntityType()->hasHandlerClass('view_builder')) {
      $display_repository->getViewDisplay($entity_type$bundle, 'full')
        ->setComponent($field_name[
          'type' => 'entity_reference_label',
        ])
        ->save();
    }
    else {
      $referenced_entity_view_mode = $this->selectViewMode($this->entity->getEntityTypeId());
      $display_repository->getViewDisplay($entity_type$bundle, 'full')
        ->setComponent($field_name[
          'type' => 'entity_reference_entity_view',
          
$doc_add_items['data']['attributes']['field_rest_test_multivalue'][2] = ['value' => '3'];
    $request_options[RequestOptions::BODY] = Json::encode($doc_add_items);
    $response = $this->request('PATCH', $url$request_options);
    $this->assertResourceResponse(200, FALSE, $response);
    $expected_document = [
      0 => ['value' => 'One'],
      1 => ['value' => 'Two'],
      2 => ['value' => '3'],
    ];
    $updated_entity = $this->entityLoadUnchanged($this->entity->id());
    $this->assertSame($expected_document$updated_entity->get('field_rest_test_multivalue')->getValue());
    if ($this->entity->getEntityType()->hasHandlerClass('moderation')) {
      $this->assertLessThan((int) $updated_entity->getRevisionId()$prior_revision_id);
    }
    else {
      $this->assertSame(static::$newRevisionsShouldBeAutomatic$prior_revision_id < (int) $updated_entity->getRevisionId());
    }

    // Ensure that PATCHing an entity that is not the latest revision is     // unsupported.     if (!$this->entity->getEntityType()->isRevisionable() || !$this->entity->getEntityType()->hasHandlerClass('moderation') || !$this->entity instanceof FieldableEntityInterface) {
      return;
    }
    
$container->set('module_handler', $module_handler->reveal());
    \Drupal::setContainer($container);

    $entity_types = [];

    $not_fieldable = $this->prophesize(EntityTypeInterface::class);
    $not_fieldable->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE);
    $entity_types['not_fieldable'] = $not_fieldable->reveal();

    $no_layout_builder_form = $this->prophesize(EntityTypeInterface::class);
    $no_layout_builder_form->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
    $no_layout_builder_form->hasHandlerClass('form', 'layout_builder')->willReturn(FALSE);
    $entity_types['no_layout_builder_form'] = $no_layout_builder_form->reveal();

    $no_view_builder = $this->prophesize(EntityTypeInterface::class);
    $no_view_builder->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
    $no_view_builder->hasHandlerClass('form', 'layout_builder')->willReturn(TRUE);
    $no_view_builder->hasViewBuilderClass()->willReturn(FALSE);
    $entity_types['no_view_builder'] = $no_view_builder->reveal();

    $no_field_ui_route = $this->prophesize(EntityTypeInterface::class);
    $no_field_ui_route->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
    $no_field_ui_route->hasHandlerClass('form', 'layout_builder')->willReturn(TRUE);
    
/** * {@inheritdoc} */
  public function getHandlerClasses() {
    return $this->handlers;
  }

  /** * {@inheritdoc} */
  public function getHandlerClass($handler_type$nested = FALSE) {
    if ($this->hasHandlerClass($handler_type$nested)) {
      $handlers = $this->getHandlerClasses();
      return $nested ? $handlers[$handler_type][$nested] : $handlers[$handler_type];
    }
    return NULL;
  }

  /** * {@inheritdoc} */
  public function setHandlerClass($handler_type$value) {
    $this->handlers[$handler_type] = $value;
    


  /** * Tests the hasHandler() method. * * @covers ::hasHandler * * @dataProvider providerTestHasHandler */
  public function testHasHandler($entity_type_id$expected) {
    $apple = $this->prophesize(EntityTypeInterface::class);
    $apple->hasHandlerClass('storage')->willReturn(TRUE);

    $banana = $this->prophesize(EntityTypeInterface::class);
    $banana->hasHandlerClass('storage')->willReturn(FALSE);

    $this->setUpEntityTypeDefinitions([
      'apple' => $apple,
      'banana' => $banana,
    ]);

    $entity_type = $this->entityTypeManager->hasHandler($entity_type_id, 'storage');
    $this->assertSame($expected$entity_type);
  }

  protected function addModerationToEntityType(ContentEntityTypeInterface $type) {
    if (!$type->hasHandlerClass('moderation')) {
      $handler_class = !empty($this->moderationHandlers[$type->id()]) ? $this->moderationHandlers[$type->id()] : ModerationHandler::class;
      $type->setHandlerClass('moderation', $handler_class);
    }

    if (!$type->hasLinkTemplate('latest-version') && $type->hasLinkTemplate('canonical')) {
      $type->setLinkTemplate('latest-version', $type->getLinkTemplate('canonical') . '/latest');
    }

    $providers = $type->getRouteProviderClasses() ?: [];
    if (empty($providers['moderation'])) {
      $providers['moderation'] = EntityModerationRouteProvider::class;
      
/** * Returns the delete multiple form route. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * The entity type. * * @return \Symfony\Component\Routing\Route|null * The generated route, if available. */
  protected function getDeleteMultipleFormRoute(EntityTypeInterface $entity_type) {
    if ($entity_type->hasLinkTemplate('delete-multiple-form') && $entity_type->hasHandlerClass('form', 'delete-multiple-confirm')) {
      $route = new Route($entity_type->getLinkTemplate('delete-multiple-form'));
      $route->setDefault('_form', $entity_type->getFormClass('delete-multiple-confirm'));
      $route->setDefault('entity_type_id', $entity_type->id());
      $route->setRequirement('_entity_delete_multiple_access', $entity_type->id());
      return $route;
    }
  }

}


  /** * Tests the correct entity types have moderation added. * * @covers ::entityTypeAlter * * @dataProvider providerTestEntityTypeAlter */
  public function testEntityTypeAlter($entity_type_id$moderatable) {
    $entity_types = $this->entityTypeManager->getDefinitions();
    $this->assertSame($moderatable$entity_types[$entity_type_id]->hasHandlerClass('moderation'));
  }

  /** * Provides test data for testEntityTypeAlter(). * * @return array * An array of test cases, where each test case is an array with the * following values: * - An entity type ID. * - Whether the entity type is moderatable or not. */
  
if (!$use_caches) {
      $this->handlers = [];
      $this->container->get('entity.memory_cache')->reset();
    }
  }

  /** * {@inheritdoc} */
  public function hasHandler($entity_type_id$handler_type) {
    if ($definition = $this->getDefinition($entity_type_id, FALSE)) {
      return $definition->hasHandlerClass($handler_type);
    }

    return FALSE;
  }

  /** * {@inheritdoc} */
  public function getStorage($entity_type_id) {
    return $this->getHandler($entity_type_id, 'storage');
  }

  


    // @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     // $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default';     // See https://www.drupal.org/node/2006348.
    // Use the add form handler, if available, otherwise default.     $operation = $entity->getEntityType()->hasHandlerClass('form', 'add') ? 'add' : 'default';

    $form_state_additions = [];
    $form_state_additions['langcode'] = $target->getId();
    $form_state_additions['content_translation']['source'] = $source;
    $form_state_additions['content_translation']['target'] = $target;
    $form_state_additions['content_translation']['translation_form'] = !$entity->access('update');

    return $this->entityFormBuilder()->getForm($entity$operation$form_state_additions);
  }

  /** * Builds the edit translation page. * * @param \Drupal\Core\Language\LanguageInterface $language * The language of the translated values. Defaults to the current content * language. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match object from which to extract the entity type. * @param string $entity_type_id * (optional) The entity type ID. * * @return array * A processed form array ready to be rendered. */

  }

  /** * 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();
    

  public function testBuildRoutes() {
    $entity_types = [];

    $not_fieldable = $this->prophesize(EntityTypeInterface::class);
    $not_fieldable->entityClassImplements(FieldableEntityInterface::class)->willReturn(FALSE);
    $entity_types['not_fieldable'] = $not_fieldable->reveal();

    $no_layout_builder_form = $this->prophesize(EntityTypeInterface::class);
    $no_layout_builder_form->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
    $no_layout_builder_form->hasHandlerClass('form', 'layout_builder')->willReturn(FALSE);
    $entity_types['no_layout_builder_form'] = $no_layout_builder_form->reveal();
    $this->entityFieldManager->getFieldStorageDefinitions('no_layout_builder_form')->shouldNotBeCalled();

    $no_view_builder = $this->prophesize(EntityTypeInterface::class);
    $no_view_builder->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
    $no_view_builder->hasViewBuilderClass()->willReturn(FALSE);
    $no_view_builder->hasHandlerClass('form', 'layout_builder')->willReturn(TRUE);
    $entity_types['no_view_builder'] = $no_view_builder->reveal();

    $no_canonical_link = $this->prophesize(EntityTypeInterface::class);
    $no_canonical_link->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
    
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)]);
  }

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