getListBuilder example



      $changes_count = [];
      foreach ($all_tracked_entities as $entity_type_id => $tracked_entities) {
        // Ensure that newest revisions are displayed at the top.         krsort($tracked_entities);

        $changes_count[$entity_type_id] = $this->entityTypeManager->getDefinition($entity_type_id)->getCountLabel(count($tracked_entities));

        $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
        if ($this->entityTypeManager->hasHandler($entity_type_id, 'list_builder')) {
          $list_builder = $this->entityTypeManager->getListBuilder($entity_type_id);
        }
        else {
          $list_builder = $this->entityTypeManager->createHandlerInstance(EntityListBuilder::class$entity_type);
        }

        $revisions = $this->entityTypeManager->getStorage($entity_type_id)->loadMultipleRevisions(array_keys($tracked_entities));

        // Load all users at once.         $user_ids = [];
        foreach ($revisions as $revision) {
          if ($revision instanceof EntityOwnerInterface) {
            

  public function listing($theme = NULL, Request $request = NULL) {
    $theme = $theme ?: $this->config('system.theme')->get('default');
    if (!$this->themeHandler->hasUi($theme)) {
      throw new NotFoundHttpException();
    }

    return $this->entityTypeManager()->getListBuilder('block')->render($theme$request);
  }

}

  public function render(ResultRow $values) {
    $entity = $this->getEntity($values);
    // Allow for the case where there is no entity, if we are on a non-required     // relationship.     if (empty($entity)) {
      return '';
    }

    $entity = $this->getEntityTranslationByRelationship($entity$values);
    $operations = $this->entityTypeManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity);
    if ($this->options['destination']) {
      foreach ($operations as &$operation) {
        if (!isset($operation['query'])) {
          $operation['query'] = [];
        }
        $operation['query'] += $this->getDestinationArray();
      }
    }
    $build = [
      '#type' => 'operations',
      '#links' => $operations,
    ];
/** * Provides the listing page for any entity type. * * @param string $entity_type * The entity type to render. * * @return array * A render array as expected by * \Drupal\Core\Render\RendererInterface::render(). */
  public function listing($entity_type) {
    return $this->entityTypeManager()->getListBuilder($entity_type)->render();
  }

}
parent::setUp();
    // Delete the override config_test entity since it is not required by this     // test.     \Drupal::entityTypeManager()->getStorage('config_test')->load('override')->delete();
    $this->drupalPlaceBlock('local_actions_block');
  }

  /** * Tests entity list builder methods. */
  public function testList() {
    $controller = \Drupal::entityTypeManager()->getListBuilder('config_test');

    // Test getStorage() method.     $this->assertInstanceOf(EntityStorageInterface::class$controller->getStorage());

    // Get a list of ConfigTest entities and confirm that it contains the     // ConfigTest entity provided by the config_test module.     // @see config_test.dynamic.dotted.default.yml     $list = $controller->load();
    $this->assertCount(1, $list, '1 ConfigTest entity found.');
    $entity = $list['dotted.default'];
    $this->assertInstanceOf(ConfigTest::class$entity);

    
/** * Load entity operations from the list builder. * * @return array * An array of operations. */
  protected function getListBuilderOperations() {

    if (is_null($this->listBuilderOperations)) {
      $this->listBuilderOperations = $this->entityTypeManager
        ->getListBuilder($this->getEntity()->getEntityTypeId())
        ->getOperations($this->getEntity());
    }

    return $this->listBuilderOperations;
  }

  /** * {@inheritdoc} */
  public function getOperations(): array {
    return $this->getListBuilderOperations();
  }

  public function listing($entity_type_id = NULL, $bundle = NULL, RouteMatchInterface $route_match = NULL) {
    return $this->entityTypeManager()->getListBuilder('field_config')->render($entity_type_id$bundle);
  }

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

    $this->installEntitySchema('node');
  }

  /** * Tests that the correct cache contexts are set. */
  public function testCacheContexts() {
    /** @var \Drupal\Core\Entity\EntityListBuilderInterface $list_builder */
    $list_builder = $this->container->get('entity_type.manager')->getListBuilder('node');

    $build = $list_builder->render();
    $this->container->get('renderer')->renderRoot($build);

    $this->assertEqualsCanonicalizing(['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'url.query_args.pagers:0', 'user.node_grants:view', 'user.permissions']$build['#cache']['contexts']);
  }

}
// Browse to the next page, test entity 51 is shown.     $this->clickLink('Page 2');
    $this->assertSession()->responseNotContains('Test entity 50');
    $this->assertSession()->pageTextContains('Test entity 51');
  }

  /** * Tests that the correct cache contexts are set. */
  public function testCacheContexts() {
    /** @var \Drupal\Core\Entity\EntityListBuilderInterface $list_builder */
    $list_builder = $this->container->get('entity_type.manager')->getListBuilder('entity_test');

    $build = $list_builder->render();
    $this->container->get('renderer')->renderRoot($build);

    $this->assertEqualsCanonicalizing(['entity_test_view_grants', 'languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'url.query_args.pagers:0', 'user.permissions']$build['#cache']['contexts']);
  }

  /** * Tests if the list cache tags are set. */
  public function testCacheTags() {
    

  public function __construct(ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer, EntityRepositoryInterface $entity_repository, PagerManagerInterface $pager_manager) {
    $this->moduleHandler = $module_handler;
    $this->entityTypeManager = $entity_type_manager;
    $this->storageController = $entity_type_manager->getStorage('taxonomy_term');
    $this->termListBuilder = $entity_type_manager->getListBuilder('taxonomy_term');
    $this->renderer = $renderer;
    $this->entityRepository = $entity_repository;
    $this->pagerManager = $pager_manager;
  }

  /** * {@inheritdoc} */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('module_handler'),
      

  public function ajaxOperation(ViewEntityInterface $view$op, Request $request) {
    // Perform the operation.     $view->$op()->save();

    // If the request is via AJAX, return the rendered list as JSON.     if ($request->request->get('js')) {
      $list = $this->entityTypeManager()->getListBuilder('view')->render();
      $response = new AjaxResponse();
      $response->addCommand(new ReplaceCommand('#views-entity-list', $list));
      return $response;
    }

    // Otherwise, redirect back to the page.     return $this->redirect('entity.view.collection');
  }

  /** * Menu callback for Views tag autocompletion. * * Like other autocomplete functions, this function inspects the 'q' query * parameter for the string to use to search for suggestions. * * @return \Symfony\Component\HttpFoundation\JsonResponse * A JSON response containing the autocomplete suggestions for Views tags. */
/** * Tests the getListBuilder() method. * * @covers ::getListBuilder */
  public function testGetListBuilder() {
    $class = $this->getTestHandlerClass();
    $entity = $this->prophesize(EntityTypeInterface::class);
    $entity->getHandlerClass('list_builder')->willReturn($class);
    $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]);

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

  /** * Tests the getViewBuilder() method. * * @covers ::getViewBuilder */
  public function testGetViewBuilder() {
    $class = $this->getTestHandlerClass();
    $entity = $this->prophesize(EntityTypeInterface::class);
    $entity->getHandlerClass('view_builder')->willReturn($class);
    
'administer nodes',
      'bypass node access',
      'administer views',
    ]);
    $this->drupalLogin($admin_user);
    $this->drupalGet('test-entity-operations');
    /** @var \Drupal\entity_test\Entity\EntityTest $entity */
    foreach ($entities as $entity) {
      /** @var \Drupal\Core\Language\LanguageInterface $language */
      foreach ($entity->getTranslationLanguages() as $language) {
        $entity = $entity->getTranslation($language->getId());
        $operations = \Drupal::service('entity_type.manager')->getListBuilder('node')->getOperations($entity);
        $this->assertNotEmpty($operations);
        foreach ($operations as $operation) {
          $expected_destination = Url::fromUri('internal:/test-entity-operations')->toString();
          // Update destination property of the URL as generating it in the           // test would by default point to the frontpage.           $operation['url']->setOption('query', ['destination' => $expected_destination]);
          $this->assertSession()->elementsCount('xpath', "//ul[contains(@class, dropbutton)]/li/a[@href='{$operation['url']->toString()}' and text()='{$operation['title']}']", 1);
          // Entities which were created in Hungarian should link to the Hungarian           // edit form, others to the English one (which has no path prefix here).           $base_path = \Drupal::request()->getBasePath();
          $parts = explode('/', str_replace($base_path, '', $operation['url']->toString()));
          
Home | Imprint | This part of the site doesn't use cookies.