You are here

protected function HttpStatusCodeDisplayVariant::variableToString in Page Manager 8.4

Convert variable to string.

Parameters

mixed $var: The variable to convert into string.

Return value

bool|string String representation for this variable.

1 call to HttpStatusCodeDisplayVariant::variableToString()
HttpStatusCodeDisplayVariant::build in src/Plugin/DisplayVariant/HttpStatusCodeDisplayVariant.php
Builds and returns the renderable array for the display variant.

File

src/Plugin/DisplayVariant/HttpStatusCodeDisplayVariant.php, line 230

Class

HttpStatusCodeDisplayVariant
Provides a variant that returns a response with an HTTP status code.

Namespace

Drupal\page_manager\Plugin\DisplayVariant

Code

protected function variableToString($var) {
  if (is_array($var)) {
    $result = FALSE;
  }
  elseif (!is_object($var)) {
    $result = settype($var, 'string') ? $var : FALSE;
  }
  elseif (is_object($var)) {
    if (method_exists($var, '__toString')) {
      $result = (string) $var;
    }
    elseif (method_exists($var, 'id')) {
      $result = $var
        ->id();
    }
    else {
      $result = FALSE;
    }
  }
  else {
    $result = FALSE;
  }
  return $result;
}