You are here

public function SimpleInstagramBlock::build in Simple Instagram Feed Block 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/Block/SimpleInstagramBlock.php \Drupal\simple_instagram_feed\Plugin\Block\SimpleInstagramBlock::build()
  2. 8.2 src/Plugin/Block/SimpleInstagramBlock.php \Drupal\simple_instagram_feed\Plugin\Block\SimpleInstagramBlock::build()
  3. 1.0.x src/Plugin/Block/SimpleInstagramBlock.php \Drupal\simple_instagram_feed\Plugin\Block\SimpleInstagramBlock::build()

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

src/Plugin/Block/SimpleInstagramBlock.php, line 232

Class

SimpleInstagramBlock
Provides a block with a dynamic Instagram Feed.

Namespace

Drupal\simple_instagram_feed\Plugin\Block

Code

public function build() {
  if (!$this->simpleInstagramFeedLibrary
    ->isAvailable()) {
    return [];
  }
  $unique_id = Html::getUniqueId($this
    ->getPluginId());
  $build = [
    '#unique_id' => $unique_id,
    '#theme' => 'simple_instagram_block',
    '#markup' => $this
      ->t('Simple Instagram Feed'),
    '#attached' => [
      'library' => [
        'simple_instagram_feed/simple_instagram_block',
      ],
      'drupalSettings' => [],
    ],
    '#cache' => [
      'max-age' => 3600,
    ],
  ];
  $build['#attached']['drupalSettings']['simple_instagram_feed'][$unique_id] = $this
    ->buildAttachedSettings();
  $build['#attached']['drupalSettings']['simple_instagram_feed'][$unique_id]['unique_id'] = $unique_id;
  return $build;
}