You are here

function CheeseburgerMenu::returnParams in Cheeseburger Menu 8.3

1 call to CheeseburgerMenu::returnParams()
CheeseburgerMenu::build in src/Plugin/Block/CheeseburgerMenu.php
Building block.

File

src/Plugin/Block/CheeseburgerMenu.php, line 620
Cheeseburger class extends BlockBase.

Class

CheeseburgerMenu
Block info.

Namespace

Drupal\cheeseburger_menu\Plugin\Block

Code

function returnParams($params) {

  /** @var \Symfony\Component\HttpFoundation\ParameterBag $params */
  $keys = $params
    ->keys();
  $route_id = 0;
  $page_type = 'unknown';
  if (count($keys) == 1) {
    $param = $params
      ->get(current($keys));
    $page_type = current($keys);
    if (is_object($param)) {
      if (method_exists($param, 'id')) {
        $route_id = $param
          ->id();
      }
      else {
        $route_id = empty($param) ? 'unknown' : $param;
      }
    }
    else {
      $route_id = empty($param) ? 'unknown' : $param;
    }
  }
  else {
    $parameters = [
      'taxonomy_term',
      'user',
      'node',
      'commerce_cart',
      'view_id',
    ];
    foreach ($parameters as $parameter) {
      if (in_array($parameter, $keys)) {
        $param = $params
          ->get($parameter);
        $page_type = $parameter;
        if (is_object($param)) {
          if (method_exists($param, 'id')) {
            $route_id = $param
              ->id();
          }
          else {
            $route_id = empty($param) ? 'unknown' : $param;
          }
        }
        else {
          $route_id = empty($param) ? 'unknown' : $param;
        }
        break;
      }
    }
  }
  return [
    'route_id' => $route_id,
    'page_type' => $page_type,
  ];
}