function CountryCodeConstraint::create

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/CountryCodeConstraint.php \Drupal\Core\Validation\Plugin\Validation\Constraint\CountryCodeConstraint::create()

Overrides ContainerFactoryPluginInterface::create

1 call to CountryCodeConstraint::create()
CountryCodeConstraintTest::testConstraintLoadsChoicesFromCountryManager in core/tests/Drupal/Tests/Core/Validation/Plugin/Validation/Constraint/CountryCodeConstraintTest.php

File

core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/CountryCodeConstraint.php, line 23

Class

CountryCodeConstraint

Namespace

Drupal\Core\Validation\Plugin\Validation\Constraint

Code

public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) : Choice {
    $countries = $container->get(CountryManagerInterface::class)
        ->getList();
    $configuration['choices'] = array_keys($countries);
    return new Choice($configuration);
}

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