You are here

public function DataPolicyInformBlock::build in Data Policy 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/DataPolicyInformBlock.php, line 141

Class

DataPolicyInformBlock
Provides a 'Data Policy' block.

Namespace

Drupal\data_policy\Plugin\Block

Code

public function build() {
  $inform_block = $this
    ->getInformBlock();
  $build['text'] = [
    '#markup' => $inform_block->summary['value'],
  ];
  if (!empty($inform_block->body['value'])) {
    $build['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $build['link'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Read more'),
      '#url' => Url::fromRoute('data_policy.description', [
        'informblock' => $inform_block
          ->id(),
      ]),
      '#attributes' => [
        'class' => [
          'use-ajax btn btn-flat',
        ],
        'data-dialog-type' => 'modal',
        'data-dialog-options' => Json::encode([
          'title' => $inform_block
            ->label(),
          'width' => 700,
        ]),
      ],
    ];
  }
  return $build;
}