本文整理汇总了PHP中Drupal\Core\Field\FieldItemBase::getConstraints方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldItemBase::getConstraints方法的具体用法?PHP FieldItemBase::getConstraints怎么用?PHP FieldItemBase::getConstraints使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Field\FieldItemBase
的用法示例。
在下文中一共展示了FieldItemBase::getConstraints方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$constraints[] = $constraint_manager->create('ComplexData', array('value' => array('TestField' => array('value' => -1, 'message' => t('%name does not accept the value @value.', array('%name' => $this->getFieldDefinition()->getLabel(), '@value' => -1))))));
return $constraints;
}
示例2: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$constraints[] = $constraint_manager->create('ComplexData', array('value' => array('Length' => array('max' => Email::EMAIL_MAX_LENGTH, 'maxMessage' => t('%name: the email address can not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getLabel(), '@max' => Email::EMAIL_MAX_LENGTH))))));
return $constraints;
}
示例3: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$constraints[] = $manager->create('ComplexData', ['amount' => ['Regex' => ['pattern' => '/^[+-]?((\\d+(\\.\\d*)?)|(\\.\\d+))$/i']]]);
return $constraints;
}
示例4: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$constraints = parent::getConstraints();
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints[] = $constraint_manager->create('ComplexData', array('name' => array('Length' => array('max' => 64, 'maxMessage' => t('%name: may not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getLabel(), '@max' => 64))))));
return $constraints;
}
示例5: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$constraints[] = $constraint_manager->create('ComplexData', array('value' => array('Length' => array('max' => static::COUNTRY_ISO2_MAXLENGTH, 'maxMessage' => t('%name: the country iso-2 code may not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getLabel(), '@max' => static::COUNTRY_ISO2_MAXLENGTH))))));
return $constraints;
}
示例6: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$settings = $this->getSettings();
$label = $this->getFieldDefinition()->getLabel();
if (!empty($settings['min'])) {
$min = $settings['min'];
$constraints[] = $constraint_manager->create('ComplexData', array('value' => array('Range' => array('min' => $min, 'minMessage' => t('%name: the value may be no less than %min.', array('%name' => $label, '%min' => $min))))));
}
if (!empty($settings['max'])) {
$max = $settings['max'];
$constraints[] = $constraint_manager->create('ComplexData', array('value' => array('Range' => array('max' => $max, 'maxMessage' => t('%name: the value may be no greater than %max.', array('%name' => $label, '%max' => $max))))));
}
return $constraints;
}
示例7: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$settings = $this->getSettings();
$label = $this->getFieldDefinition()->getLabel();
if (!empty($settings['opacity'])) {
$min = 0;
$constraints[] = $constraint_manager->create('ComplexData', array('opacity' => array('Range' => array('min' => $min, 'minMessage' => t('%name: the opacity may be no less than %min.', array('%name' => $label, '%min' => $min))))));
$max = 1;
$constraints[] = $constraint_manager->create('ComplexData', array('opacity' => array('Range' => array('max' => $max, 'maxMessage' => t('%name: the opacity may be no greater than %max.', array('%name' => $label, '%max' => $max))))));
}
// @todo: Adapt constraint based on storage.
//$constraints[] = $constraint_manager->create('ComplexData', array(
// 'color' => array(
// 'Regex' => array(
// 'pattern' => '/^#(\d+)$/i',
// )
// ),
//));
return $constraints;
}
示例8: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$constraints = parent::getConstraints();
return $constraints;
}
示例9: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$constraints = parent::getConstraints();
$manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$availableCountries = $this->getAvailableCountries();
$enabledFields = array_filter($this->getSetting('fields'));
$constraints[] = $manager->create('Country', ['availableCountries' => $availableCountries]);
$constraints[] = $manager->create('AddressFormat', ['fields' => $enabledFields]);
return $constraints;
}
示例10: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$constraints = parent::getConstraints();
// Remove the 'AllowedValuesConstraint' validation constraint because entity
// reference fields already use the 'ValidReference' constraint.
foreach ($constraints as $key => $constraint) {
if ($constraint instanceof AllowedValuesConstraint) {
unset($constraints[$key]);
}
}
return $constraints;
}
示例11: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$constraints = parent::getConstraints();
list($current_handler) = explode(':', $this->getSetting('handler'), 2);
if ($current_handler === 'default') {
$handler_settings = $this->getSetting('handler_settings');
if (!empty($handler_settings['target_bundles'])) {
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints[] = $constraint_manager->create('ComplexData', ['entity' => ['Bundle' => ['bundle' => $handler_settings['target_bundles']]]]);
}
}
return $constraints;
}
示例12: getConstraints
/**
* {@inheritdoc}
*
* @DSG: Optional.
*/
public function getConstraints()
{
$constraints = parent::getConstraints();
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
// @DCG: Assume our value should not be longer than 50 characters.
$options['value']['Length']['max'] = 50;
// @DSG: See \Drupal\Core\Validation\Plugin\Validation\Constraint\* for
// @DCG: available constraints.
$constraints[] = $constraint_manager->create('ComplexData', $options);
return $constraints;
}
示例13: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
return parent::getConstraints();
}
示例14: getConstraints
/**
* {@inheritdoc}
*
* @TODO: Find a way to disable constraints for default field values.
*/
public function getConstraints()
{
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$settings = $this->getSettings();
$subconstrains = [];
foreach (['first', 'second'] as $subfield) {
$subfield_type = $settings['storage'][$subfield]['type'];
if (!in_array($subfield_type, ['boolean', 'text']) && $settings[$subfield]['list'] && $settings[$subfield]['allowed_values']) {
$allowed_values = array_keys($settings[$subfield]['allowed_values']);
$subconstrains[$subfield]['AllowedValues'] = $allowed_values;
}
if ($subfield_type == 'string') {
$subconstrains[$subfield]['Length']['max'] = $settings['storage'][$subfield]['maxlength'];
}
// Allowed values take precedence over the range constraints.
if (!$settings[$subfield]['list'] && in_array($subfield_type, ['integer', 'float', 'numeric'])) {
if (is_numeric($settings[$subfield]['min'])) {
$subconstrains[$subfield]['Range']['min'] = $settings[$subfield]['min'];
}
if (is_numeric($settings[$subfield]['max'])) {
$subconstrains[$subfield]['Range']['max'] = $settings[$subfield]['max'];
}
}
if ($subfield_type == 'email') {
$subconstrains[$subfield]['Length']['max'] = Email::EMAIL_MAX_LENGTH;
}
// This is applicable to all types.
if ($settings[$subfield]['required']) {
$subconstrains[$subfield]['NotBlank'] = [];
}
}
$constraints[] = $constraint_manager->create('ComplexData', $subconstrains);
return $constraints;
}
示例15: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$constraints = parent::getConstraints();
// Remove the 'AllowedValuesConstraint' validation constraint because entity
// reference fields already use the 'ValidReference' constraint.
foreach ($constraints as $key => $constraint) {
if ($constraint instanceof AllowedValuesConstraint) {
unset($constraints[$key]);
}
}
list($current_handler) = explode(':', $this->getSetting('handler'), 2);
if ($current_handler === 'default') {
$handler_settings = $this->getSetting('handler_settings');
if (isset($handler_settings['target_bundles'])) {
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints[] = $constraint_manager->create('ComplexData', ['entity' => ['Bundle' => ['bundle' => $handler_settings['target_bundles']]]]);
}
}
return $constraints;
}