当前位置: 首页>>代码示例>>PHP>>正文


PHP FieldItemBase::getConstraints方法代码示例

本文整理汇总了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;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:10,代码来源:TestItem.php

示例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;
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:10,代码来源:EmailItem.php

示例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;
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:10,代码来源:Price.php

示例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;
 }
开发者ID:novaFTL,项目名称:quiz-drupal8,代码行数:10,代码来源:MultipleChoice.php

示例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;
 }
开发者ID:C4AProjects,项目名称:c4apage,代码行数:10,代码来源:CountryItem.php

示例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;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:19,代码来源:NumericItemBase.php

示例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;
 }
开发者ID:zindont,项目名称:emormapping,代码行数:25,代码来源:ColorFieldType.php

示例8: getConstraints

 /**
  * {@inheritdoc}
  */
 public function getConstraints()
 {
     $constraints = parent::getConstraints();
     return $constraints;
 }
开发者ID:novaFTL,项目名称:quiz-drupal8,代码行数:8,代码来源:TrueFalseFieldType.php

示例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;
 }
开发者ID:jokas,项目名称:d8.dev,代码行数:13,代码来源:AddressItem.php

示例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;
 }
开发者ID:318io,项目名称:318-io,代码行数:15,代码来源:EntityReferenceItem.php

示例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;
 }
开发者ID:komejo,项目名称:article-test,代码行数:16,代码来源:EntityReferenceItem.php

示例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;
 }
开发者ID:chi-teck,项目名称:drupal-code-generator,代码行数:16,代码来源:_field_type.php

示例13: getConstraints

 /**
  * {@inheritdoc}
  */
 public function getConstraints()
 {
     return parent::getConstraints();
 }
开发者ID:WondrousLLC,项目名称:contact_form_field,代码行数:7,代码来源:ContactFormFieldType.php

示例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;
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:40,代码来源:DoubleField.php

示例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;
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:23,代码来源:EntityReferenceItem.php


注:本文中的Drupal\Core\Field\FieldItemBase::getConstraints方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。