alterBuild example

$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);

        // Assign the weights configured in the display.         // @todo Once https://www.drupal.org/node/1875974 provides the missing         // API, only do it for 'extra fields', since other components have         // been taken care of in EntityViewDisplay::buildMultiple().         foreach ($display->getComponents() as $name => $options) {
          if (isset($build_list[$key][$name])) {
            $build_list[$key][$name]['#weight'] = $options['weight'];
          }
        }

        

    if ($build[$id]['#comment_threaded']) {
      // The final comment must close up some hanging divs.       $build[$id]['#comment_indent_final'] = $current_indent;
    }
  }

  /** * {@inheritdoc} */
  protected function alterBuild(array &$build, EntityInterface $comment, EntityViewDisplayInterface $display$view_mode) {
    parent::alterBuild($build$comment$display$view_mode);
    if (empty($comment->in_preview)) {
      $prefix = '';

      // Add indentation div or close open divs as needed.       if ($build['#comment_threaded']) {
        $prefix .= $build['#comment_indent'] <= 0 ? str_repeat('</div>', abs($build['#comment_indent'])) : "\n" . '<div class="indented">';
      }

      $build['#prefix'] = $prefix;

      // Close all open divs.
Home | Imprint | This part of the site doesn't use cookies.