You are here

public function PoweredByBlock::build in Ubercart 8.4

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

uc_store/src/Plugin/Block/PoweredByBlock.php, line 119

Class

PoweredByBlock
Provides a block to identify Ubercart as the store software on a site.

Namespace

Drupal\uc_store\Plugin\Block

Code

public function build() {
  $id = $this->configuration['message'];

  // Figure out what page is being viewed.
  $path = $this->routeMatch
    ->getRouteName();
  $messages = $this
    ->options();
  if ($id == 0) {

    // Calculate which message to show based on a hash of the path and the
    // site's private key. The message initially chosen for each page on a
    // specific site will thus be pseudo-random, yet we will consistently
    // display the same message on any given page on that site, thus allowing
    // pages to be cached.
    $private_key = $this->privateKey
      ->get();
    $id = hexdec(substr(md5($path . $private_key), 0, 2)) % count($messages) + 1;
  }
  return [
    '#markup' => $messages[$id],
  ];
}