You are here

public function BlazyManager::build in Blazy 8.2

Same name and namespace in other branches
  1. 7 src/BlazyManager.php \Drupal\blazy\BlazyManager::build()

Returns the contents using theme_field(), or theme_item_list().

Blazy outputs can be formatted using either flat list via theme_field(), or a grid of Field items or Views rows via theme_item_list().

Parameters

array $build: The array containing: settings, children elements, or optional items.

Return value

array The alterable and renderable array of contents.

File

src/BlazyManager.php, line 445

Class

BlazyManager
Implements a public facing blazy manager.

Namespace

Drupal\blazy

Code

public function build(array $build = []) {
  $settings =& $build['settings'];
  $settings['_grid'] = isset($settings['_grid']) ? $settings['_grid'] : !empty($settings['style']) && !empty($settings['grid']);

  // If not a grid, pass the items as regular index children to theme_field().
  // This #pre_render doesn't work if called from Views results, hence the
  // output is split either as theme_field() or theme_item_list().
  if (empty($settings['_grid'])) {
    $settings = $this
      ->getSettings($build);

    // Runs after ::getSettings.
    $this
      ->prepareBuild($build);
    $build['#blazy'] = $settings;
    $this
      ->setAttachments($build, $settings);
  }
  else {

    // Take over theme_field() with a theme_item_list(), if so configured.
    // The reason: this is not only fed by field items, but also Views rows.
    $content = [
      '#build' => $build,
      '#pre_render' => [
        [
          $this,
          'preRenderBuild',
        ],
      ],
    ];

    // Yet allows theme_field(), if so required, such as for linked_field.
    $build = empty($settings['use_field']) ? $content : [
      $content,
    ];
  }
  $this->moduleHandler
    ->alter('blazy_build', $build, $settings);
  return $build;
}