You are here

public function AboutOpignoBlock::build in Opigno dashboard 3.x

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/AboutOpignoBlock.php, line 63

Class

AboutOpignoBlock
About Opigno block.

Namespace

Drupal\opigno_dashboard\Plugin\Block

Code

public function build() {
  if ($this->account
    ->isAnonymous()) {
    return [
      '#cache' => [
        'max-age' => -1,
      ],
    ];
  }
  $build = [
    '#cache' => [
      'tags' => $this
        ->getCacheTags(),
      'contexts' => $this
        ->getCacheContexts(),
    ],
  ];

  // The block should be accessible only for admin users.
  if (!$this->account
    ->hasPermission('access administration pages')) {
    return $build;
  }
  $logo = theme_get_setting('logo_path_anonymous');
  if (!is_file($logo)) {
    $logo = drupal_get_path('theme', 'aristotle') . '/assets/' . $logo;
  }
  $options = [
    'attributes' => [
      'target' => '_blank',
    ],
  ];
  $url = Url::fromUri('https://www.opigno.org', $options);
  return [
    '#theme' => 'opigno_about_block',
    '#logo' => file_exists($logo) ? file_url_transform_relative(file_create_url($logo)) : '',
    '#texts' => [
      $this
        ->t('Opigno™ is a Trademark of Connect-i Sàrl, based in Préverenges, Switzerland.'),
      $this
        ->t('For more information regarding Opigno™ please consult the website @link.', [
        '@link' => Link::fromTextAndUrl('www.opigno.org', $url)
          ->toString(),
      ]),
    ],
    '#version' => opigno_lms_get_current_opigno_lms_release() ?: '3.0',
  ] + $build;
}