You are here

function vardumper_block_block_view in VarDumper 7

Implements hook_block_view().

File

modules/vardumper_block/vardumper_block.module, line 22
Main module file for the vardumper_block module.

Code

function vardumper_block_block_view($delta = '') {
  $content = NULL;
  $block = array();
  $items = array();

  // Do not display anything if user do not have the permission.
  if (!user_access('access vardumper information')) {
    return array(
      'subject' => t('Debugging block'),
      'content' => NULL,
    );
  }

  /* @var \Symfony\Component\HttpFoundation\Session\Session $session */
  $session = \Drupal::service('vardumper_session');
  foreach ($session
    ->getFlashBag()
    ->get('vardumper', array()) as $message) {
    $items[] = $message;
  }
  if (!empty($items)) {
    $content = array(
      '#theme' => 'item_list',
      '#items' => $items,
    );
  }
  switch ($delta) {
    case 'vardumper':
      $block['subject'] = t('Debugging block');
      $block['content'] = $content;
  }
  return $block;
}