Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Timezone.php

class Timezone

Same name in this branch
  1. 11.1.x core/modules/system/src/Plugin/migrate/process/d6/TimeZone.php \Drupal\system\Plugin\migrate\process\d6\TimeZone

Validates that a value is a valid timezone identifier.

@author Javier Spagnoletti <phansys@gmail.com> @author Hugo Hamon <hugohamon@neuf.fr>

Hierarchy

  • class \Symfony\Component\Validator\Constraint
    • class \Symfony\Component\Validator\Constraints\Timezone extends \Symfony\Component\Validator\Constraint

Expanded class hierarchy of Timezone

17 string references to 'Timezone'
AccountForm::flagViolations in core/modules/user/src/AccountForm.php
Flags violations for the current form.
AccountForm::getEditedFieldNames in core/modules/user/src/AccountForm.php
Gets the names of all fields edited in the form.
CoreExtension::getAttribute in vendor/twig/twig/src/Extension/CoreExtension.php
Returns the attribute value for a given array/object.
d6_system_date.yml in core/modules/system/migrations/d6_system_date.yml
core/modules/system/migrations/d6_system_date.yml
d6_user.yml in core/modules/user/migrations/d6_user.yml
core/modules/user/migrations/d6_user.yml

... See full list

File

vendor/symfony/validator/Constraints/Timezone.php, line 23

Namespace

Symfony\Component\Validator\Constraints
View source
class Timezone extends Constraint {
    public const TIMEZONE_IDENTIFIER_ERROR = '5ce113e6-5e64-4ea2-90fe-d2233956db13';
    public const TIMEZONE_IDENTIFIER_IN_ZONE_ERROR = 'b57767b1-36c0-40ac-a3d7-629420c775b8';
    public const TIMEZONE_IDENTIFIER_IN_COUNTRY_ERROR = 'c4a22222-dc92-4fc0-abb0-d95b268c7d0b';
    public const TIMEZONE_IDENTIFIER_INTL_ERROR = '45863c26-88dc-41ba-bf53-c73bd1f7e90d';
    public int $zone = \DateTimeZone::ALL;
    public ?string $countryCode = null;
    public bool $intlCompatible = false;
    public string $message = 'This value is not a valid timezone.';
    protected const ERROR_NAMES = [
        self::TIMEZONE_IDENTIFIER_ERROR => 'TIMEZONE_IDENTIFIER_ERROR',
        self::TIMEZONE_IDENTIFIER_IN_ZONE_ERROR => 'TIMEZONE_IDENTIFIER_IN_ZONE_ERROR',
        self::TIMEZONE_IDENTIFIER_IN_COUNTRY_ERROR => 'TIMEZONE_IDENTIFIER_IN_COUNTRY_ERROR',
        self::TIMEZONE_IDENTIFIER_INTL_ERROR => 'TIMEZONE_IDENTIFIER_INTL_ERROR',
    ];
    
    /**
     * @param int|array<string,mixed>|null $zone           Restrict valid timezones to this geographical zone (defaults to {@see \DateTimeZone::ALL})
     * @param string|null                  $countryCode    Restrict the valid timezones to this country if the zone option is {@see \DateTimeZone::PER_COUNTRY}
     * @param bool|null                    $intlCompatible Whether to restrict valid timezones to ones available in PHP's intl (defaults to false)
     * @param string[]|null                $groups
     * @param array<string,mixed>          $options
     *
     * @see \DateTimeZone
     */
    public function __construct(int|array|null $zone = null, ?string $message = null, ?string $countryCode = null, ?bool $intlCompatible = null, ?array $groups = null, mixed $payload = null, array $options = []) {
        if (\is_array($zone)) {
            $options = array_merge($zone, $options);
        }
        elseif (null !== $zone) {
            $options['value'] = $zone;
        }
        parent::__construct($options, $groups, $payload);
        $this->message = $message ?? $this->message;
        $this->countryCode = $countryCode ?? $this->countryCode;
        $this->intlCompatible = $intlCompatible ?? $this->intlCompatible;
        if (null === $this->countryCode) {
            if (0 >= $this->zone || \DateTimeZone::ALL_WITH_BC < $this->zone) {
                throw new ConstraintDefinitionException('The option "zone" must be a valid range of "\\DateTimeZone" constants.');
            }
        }
        elseif (\DateTimeZone::PER_COUNTRY !== (\DateTimeZone::PER_COUNTRY & $this->zone)) {
            throw new ConstraintDefinitionException('The option "countryCode" can only be used when the "zone" option is configured with "\\DateTimeZone::PER_COUNTRY".');
        }
        if ($this->intlCompatible && !class_exists(\IntlTimeZone::class)) {
            throw new ConstraintDefinitionException('The option "intlCompatible" can only be used when the PHP intl extension is available.');
        }
    }
    public function getDefaultOption() : ?string {
        return 'zone';
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Constraint::$groups public property The groups that the constraint belongs to.
Constraint::$payload public property Domain-specific data attached to a constraint.
Constraint::addImplicitGroupName public function Adds the given group if this constraint is in the Default group. 2
Constraint::CLASS_CONSTRAINT public constant Marks a constraint that can be put onto classes.
Constraint::DEFAULT_GROUP public constant The name of the group given to all constraints with no explicit group.
Constraint::getErrorName public static function Returns the name of the given error code.
Constraint::getRequiredOptions public function Returns the name of the required options. 22
Constraint::getTargets public function Returns whether the constraint can be put onto classes, properties or
both.
8
Constraint::normalizeOptions protected function
Constraint::PROPERTY_CONSTRAINT public constant Marks a constraint that can be put onto properties.
Constraint::validatedBy public function Returns the name of the class that validates this constraint. 9
Constraint::__get public function Returns the value of a lazily initialized option. 2
Constraint::__isset public function 1
Constraint::__set public function Sets the value of a lazily initialized option. 1
Constraint::__sleep public function Optimizes the serialized value to minimize storage space.
Timezone::$countryCode public property
Timezone::$intlCompatible public property
Timezone::$message public property
Timezone::$zone public property
Timezone::ERROR_NAMES protected constant Maps error codes to the names of their constants. Overrides Constraint::ERROR_NAMES
Timezone::getDefaultOption public function Returns the name of the default option. Overrides Constraint::getDefaultOption
Timezone::TIMEZONE_IDENTIFIER_ERROR public constant
Timezone::TIMEZONE_IDENTIFIER_INTL_ERROR public constant
Timezone::TIMEZONE_IDENTIFIER_IN_COUNTRY_ERROR public constant
Timezone::TIMEZONE_IDENTIFIER_IN_ZONE_ERROR public constant
Timezone::__construct public function Overrides Constraint::__construct
RSS feed
Powered by Drupal