You are here

public static function Helper::getCurrentPageMeta in Structured Data (JSON+LD Rich Snippets) 8

Get current page meta data.

Parameters

bool $fillEmptyValues: Defaults to FALSE.

Return value

array An array of meta data.

2 calls to Helper::getCurrentPageMeta()
structured_data_page_attachments_alter in ./structured_data.module
Implements hook_page_attachments_alter().
structured_data_toolbar_alter in ./structured_data.module
Implements hook_toolbar_alter().

File

src/Core/Helper.php, line 25

Class

Helper
Class Helper.

Namespace

Drupal\structured_data\Core

Code

public static function getCurrentPageMeta($fillEmptyValues = FALSE) {
  $route = \Drupal::routeMatch();
  $route_name = $route
    ->getRouteName();
  $url = Url::fromRoute('<current>');
  $urlString = $url
    ->toString();
  $matches = [];
  $result = preg_match("/entity\\.([a-zA-Z0-9_]+)\\.canonical/", $route_name, $matches);
  if ($result == 1) {
    $bundle = $matches[1];
    $entity_id = $route
      ->getRawParameter($bundle);
  }
  else {
    $bundle = $fillEmptyValues ? self::EMPTY_BUNDLE : '';
    $entity_id = $fillEmptyValues ? '0' : '';
  }
  $meta = [
    'route_name' => $route_name,
    'url' => $urlString,
    'bundle' => $bundle,
    'entity_id' => $entity_id,
  ];
  return $meta;
}