You are here

public function ShariffBlock::build in Shariff Social Media Buttons 8

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/ShariffBlock.php, line 24

Class

ShariffBlock
Provides a 'shariff' block.

Namespace

Drupal\shariff\Plugin\Block

Code

public function build() {
  $config = $this
    ->getConfiguration();
  $shariff_settings = [];
  foreach ($config as $setting => $value) {

    // Only set shariff settings as variable.
    if (substr($setting, 0, strlen('shariff')) === 'shariff') {
      $shariff_settings[$setting] = $value;
    }
  }

  // Set variable when block should overwrite default settings.
  $blocksettings = isset($config['shariff_default_settings']) && $config['shariff_default_settings'] ? NULL : $shariff_settings;
  $block = [
    '#theme' => 'block_shariff',
    '#blocksettings' => $blocksettings,
    '#attached' => [
      'library' => [
        'shariff/shariff',
      ],
    ],
  ];
  return $block;
}