function PluralTranslation::__construct

Same name in other branches
  1. 9 core/lib/Drupal/Core/Annotation/PluralTranslation.php \Drupal\Core\Annotation\PluralTranslation::__construct()
  2. 8.9.x core/lib/Drupal/Core/Annotation/PluralTranslation.php \Drupal\Core\Annotation\PluralTranslation::__construct()
  3. 11.x core/lib/Drupal/Core/Annotation/PluralTranslation.php \Drupal\Core\Annotation\PluralTranslation::__construct()

Constructs a new class instance.

Parameters

array $values: An associative array with the following keys:

  • singular: The string for the singular case.
  • plural: The string for the plural case.
  • context: The context the source strings belong to.

Throws

\InvalidArgumentException Thrown when the keys 'singular' or 'plural' are missing from the $values array.

File

core/lib/Drupal/Core/Annotation/PluralTranslation.php, line 79

Class

PluralTranslation
Defines an annotation object for strings that require plural forms.

Namespace

Drupal\Core\Annotation

Code

public function __construct(array $values) {
    if (!isset($values['singular'])) {
        throw new \InvalidArgumentException('Missing "singular" value in the PluralTranslation annotation');
    }
    if (!isset($values['plural'])) {
        throw new \InvalidArgumentException('Missing "plural" value in the PluralTranslation annotation');
    }
    $this->singular = $values['singular'];
    $this->plural = $values['plural'];
    if (isset($values['context'])) {
        $this->context = $values['context'];
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.