Unverified Commit bc383a3b authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3437499 by catch, kristiaanvandeneynde, oily, berdir: Use placeholdering for more blocks

parent 9525aa6d
Loading
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -76,6 +76,19 @@ public function access(AccountInterface $account, $return_as_object = FALSE);
   */
  public function build();

  /**
   * Whether to render blocks in a placeholder.
   *
   * When blocks of this type are rendered, indicate whether they should be
   * rendered in a placeholder or not. In general, blocks that attach libraries
   * and/or render entities should be placeholdered to optimize various aspects
   * of rendering performance.
   *
   * @return bool
   *   Whether to placeholder blocks of this plugin type.
   */
  public function createPlaceholder(): bool;

  /**
   * Sets a particular value in the block settings.
   *
+7 −0
Original line number Diff line number Diff line
@@ -296,4 +296,11 @@ public function setInPreview(bool $in_preview): void {
    $this->inPreview = $in_preview;
  }

  /**
   * {@inheritdoc}
   */
  public function createPlaceholder(): bool {
    return FALSE;
  }

}
+7 −0
Original line number Diff line number Diff line
@@ -83,4 +83,11 @@ public function build() {
    return $local_actions;
  }

  /**
   * {@inheritdoc}
   */
  public function createPlaceholder(): bool {
    return TRUE;
  }

}
+7 −0
Original line number Diff line number Diff line
@@ -165,4 +165,11 @@ public function blockSubmit($form, FormStateInterface $form_state) {
    $this->configuration['secondary'] = $levels['secondary'];
  }

  /**
   * {@inheritdoc}
   */
  public function createPlaceholder(): bool {
    return TRUE;
  }

}
+7 −0
Original line number Diff line number Diff line
@@ -75,6 +75,13 @@ public function viewMultiple(array $entities = [], $view_mode = 'full', $langcod
        $build[$entity_id] += [
          '#lazy_builder' => [static::class . '::lazyBuilder', [$entity_id, $view_mode, $langcode]],
        ];
        // Only add create_placeholder if it's explicitly set to TRUE, so it can
        // be set to TRUE by automatic placeholdering conditions if it's absent.
        if ($plugin->createPlaceholder()) {
          $build[$entity_id] += [
            '#create_placeholder' => TRUE,
          ];
        }
      }
    }

Loading