You are here

public function HttpStatusCode::summary in Context 8.4

Provides a human readable summary of the condition's configuration.

Overrides ConditionInterface::summary

File

src/Plugin/Condition/HttpStatusCode.php, line 87

Class

HttpStatusCode
Provides a 'Http status code' condition.

Namespace

Drupal\context\Plugin\Condition

Code

public function summary() {
  if (empty($this->configuration['status_codes'])) {
    return $this
      ->t('The http status code is not specified');
  }
  if (count($this->configuration['status_codes']) > 1) {
    $status_codes = $this->configuration['status_codes'];
    $last = array_pop($status_codes);
    $status_codes = implode(', ', $status_codes);
    if ($this
      ->isNegated()) {
      return $this
        ->t('The http status code is not @status_codes or @last', [
        '@status_codes' => $status_codes,
        '@last' => $last,
      ]);
    }
    return $this
      ->t('The http status code is @status_codes or @last', [
      '@status_codes' => $status_codes,
      '@last' => $last,
    ]);
  }
  $status_code = reset($this->configuration['status_codes']);
  if ($this
    ->isNegated()) {
    return $this
      ->t('The http status code is not @status_code', [
      '@status_code' => $status_code,
    ]);
  }
  return $this
    ->t('The http status code is @status_code', [
    '@status_code' => $status_code,
  ]);
}