當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。