You are here

function _sharerich_get_token_data in Sharerich 8

Helper to return the data to be used when rendering tokens.

Return value

array

1 call to _sharerich_get_token_data()
SharerichBlock::build in src/Plugin/Block/SharerichBlock.php
Builds and returns the renderable array for this block plugin.

File

./sharerich.module, line 110
Contains sharerich.module..

Code

function _sharerich_get_token_data() {
  $route = \Drupal::request()->attributes
    ->get(RouteObjectInterface::ROUTE_NAME);
  switch ($route) {
    case 'entity.node.canonical':
      $data = [
        'node' => \Drupal::request()->attributes
          ->get('node'),
      ];
      break;
    case 'entity.taxonomy_term.canonical':
      $data = [
        'taxonomy_term' => \Drupal::request()->attributes
          ->get('taxonomy_term'),
      ];
      break;
    case 'entity.user.canonical':
      $data = [
        'user' => \Drupal::request()->attributes
          ->get('user'),
      ];
      break;
    default:
      $data = [];
  }
  return $data;
}