buildComponents example

$instance->entityTypeManager = $container->get('entity_type.manager');
    $instance->workspaceAssociation = $container->get('workspaces.association');
    $instance->dateFormatter = $container->get('date.formatter');
    $instance->bundleInfo = $container->get('entity_type.bundle.info');
    return $instance;
  }

  /** * {@inheritdoc} */
  public function buildComponents(array &$build, array $entities, array $displays$view_mode) {
    parent::buildComponents($build$entities$displays$view_mode);
    $bundle_info = $this->bundleInfo->getAllBundleInfo();

    $header = [
      'title' => $this->t('Title'),
      'type' => $this->t('Type'),
      'changed' => $this->t('Last changed'),
      'owner' => $this->t('Author'),
      'operations' => $this->t('Operations'),
    ];
    foreach ($entities as $build_id => $entity) {
      $all_tracked_entities = $this->workspaceAssociation->getTrackedEntities($entity->id());

      
if (empty($entities)) {
      return;
    }

    // Pre-load associated users into cache to leverage multiple loading.     $uids = [];
    foreach ($entities as $entity) {
      $uids[] = $entity->getOwnerId();
    }
    $this->entityTypeManager->getStorage('user')->loadMultiple(array_unique($uids));

    parent::buildComponents($build$entities$displays$view_mode);

    // A counter to track the indentation level.     $current_indent = 0;
    $attach_history = $this->moduleHandler->moduleExists('history') && $this->currentUser->isAuthenticated();

    foreach ($entities as $id => $entity) {
      if ($build[$id]['#comment_threaded']) {
        $comment_indent = count(explode('.', (string) $entity->getThread())) - 1;
        if ($comment_indent > $current_indent) {
          // Set 1 to indent this comment from the previous one (its parent).           // Set only one extra level of indenting even if the difference in
class NodeViewBuilder extends EntityViewBuilder implements TrustedCallbackInterface {

  /** * {@inheritdoc} */
  public function buildComponents(array &$build, array $entities, array $displays$view_mode) {
    /** @var \Drupal\node\NodeInterface[] $entities */
    if (empty($entities)) {
      return;
    }

    parent::buildComponents($build$entities$displays$view_mode);

    foreach ($entities as $id => $entity) {
      $bundle = $entity->bundle();
      $display = $displays[$bundle];

      if ($display->getComponent('links')) {
        $build[$id]['links'] = [
          '#lazy_builder' => [
            static::class D '::renderLinks', [
              $entity->id(),
              $view_mode,
              
/** * Defines an entity view builder for a test entity. * * @see \Drupal\entity_test\Entity\EntityTestRender */
class EntityTestViewBuilder extends EntityViewBuilder {

  /** * {@inheritdoc} */
  public function buildComponents(array &$build, array $entities, array $displays$view_mode) {
    parent::buildComponents($build$entities$displays$view_mode);

    foreach ($entities as $id => $entity) {
      $build[$id]['label'] = [
        '#weight' => -100,
        '#plain_text' => $entity->label(),
      ];
      $build[$id]['separator'] = [
        '#weight' => -150,
        '#markup' => ' | ',
      ];
      $build[$id]['view_mode'] = [
        
if (isset($build_list[$key][$entity_type_key])) {
        $entity = $build_list[$key][$entity_type_key];
        if ($entity instanceof FieldableEntityInterface) {
          $view_modes[$build_list[$key]['#view_mode']][$key] = $entity;
        }
      }
    }

    // Build content for the displays represented by the entities.     foreach ($view_modes as $view_mode => $view_mode_entities) {
      $displays = EntityViewDisplay::collectRenderDisplays($view_mode_entities$view_mode);
      $this->buildComponents($build_list$view_mode_entities$displays$view_mode);
      foreach (array_keys($view_mode_entities) as $key) {
        // Allow for alterations while building, before rendering.         $entity = $build_list[$key][$entity_type_key];
        $display = $displays[$entity->bundle()];

        $this->moduleHandler()->invokeAll($view_hook[&$build_list[$key]$entity$display$view_mode]);
        $this->moduleHandler()->invokeAll('entity_view', [&$build_list[$key]$entity$display$view_mode]);

        $this->addContextualLinks($build_list[$key]$entity);
        $this->alterBuild($build_list[$key]$entity$display$view_mode);

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