You are here

public function BlazyManager::build in Blazy 7

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

Returns the entire contents using theme_field(), or 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 359

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().
  // Separated since #pre_render doesn't work if called from Views results.
  if (empty($settings['_grid'])) {
    $settings = $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' => [
        'blazy_pre_render_build',
      ],
    ];

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