當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Field\FieldItemBase類代碼示例

本文整理匯總了PHP中Drupal\Core\Field\FieldItemBase的典型用法代碼示例。如果您正苦於以下問題:PHP FieldItemBase類的具體用法?PHP FieldItemBase怎麽用?PHP FieldItemBase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FieldItemBase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例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: onChange

 /**
  * {@inheritdoc}
  */
 public function onChange($property_name)
 {
     parent::onChange($property_name);
     // Enforce that the computed date is recalculated.
     if ($property_name == 'value') {
         $this->date = NULL;
     }
 }
開發者ID:alnutile,項目名稱:drunatra,代碼行數:11,代碼來源:DateTimeItem.php

示例7: fieldSettingsForm

 /**
  * {@inheritdoc}
  */
 public function fieldSettingsForm(array $form, FormStateInterface $form_state)
 {
     $element = parent::fieldSettingsForm($form, $form_state);
     $range = $this->getSetting('range');
     $element['range'] = array('#type' => 'textfield', '#title' => t('Range'), '#description' => t('The range of weights available to select. For
     example, a range of 20 will allow you to select a weight between -20
     and 20.'), '#default_value' => $range, '#size' => 5);
     return $element;
 }
開發者ID:k-zafar,項目名稱:barney_river,代碼行數:12,代碼來源:WeightItem.php

示例8: setValue

 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     if (empty($values['data'])) {
         $values['data'] = NULL;
     } else {
         $deserialized_data = unserialize((string) $values['data']);
         $values['data'] = is_array($deserialized_data) ? $deserialized_data : NULL;
     }
     parent::setValue($values, $notify);
 }
開發者ID:pedrocones,項目名稱:geolocation,代碼行數:13,代碼來源:GeolocationItem.php

示例9: setValue

 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     // Unserialize the values.
     // @todo The storage controller should take care of this, see
     //   SqlContentEntityStorage::loadFieldItems, see
     //   https://www.drupal.org/node/2414835
     if (isset($values['query']) && is_string($values['query'])) {
         $values['query'] = unserialize($values['query']);
     }
     parent::setValue($values, $notify);
 }
開發者ID:aakb,項目名稱:cfia,代碼行數:14,代碼來源:RedirectSourceItem.php

示例10: onChange

 /**
  * {@inheritdoc}
  */
 public function onChange($property_name, $notify = TRUE)
 {
     // Unset processed properties that are affected by the change.
     foreach ($this->definition->getPropertyDefinitions() as $property => $definition) {
         if ($definition->getClass() == '\\Drupal\\text\\TextProcessed') {
             if ($property_name == 'format' || $definition->getSetting('text source') == $property_name) {
                 $this->writePropertyValue($property, NULL);
             }
         }
     }
     parent::onChange($property_name, $notify);
 }
開發者ID:nstielau,項目名稱:drops-8,代碼行數:15,代碼來源:TextItemBase.php

示例11: setValue

 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     // Treat the values as property value of the first property, if no array is
     // given.
     if (is_string($values)) {
         $values = unserialize($values);
         if (!is_array($values)) {
             $values = array();
         }
     }
     $values = array('value' => $values);
     parent::setValue($values, $notify);
 }
開發者ID:alnutile,項目名稱:drunatra,代碼行數:16,代碼來源:SerializedItem.php

示例12: 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

示例13: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave()
 {
     parent::preSave();
     // Merge field defaults on top of global ones.
     $default_tags = metatag_get_default_tags();
     // Get the value about to be saved.
     $current_value = $this->value;
     $current_tags = unserialize($current_value);
     // Only include values that differ from the default.
     // @TODO: When site defaults are added, account for those.
     $tags_to_save = [];
     foreach ($current_tags as $tag_id => $tag_value) {
         if (!isset($default_tags[$tag_id]) || $tag_value != $default_tags[$tag_id]) {
             $tags_to_save[$tag_id] = $tag_value;
         }
     }
     // Update the value to only save overridden tags.
     $this->value = serialize($tags_to_save);
 }
開發者ID:eric-shell,項目名稱:eric-shell-d8,代碼行數:22,代碼來源:MetatagFieldItem.php

示例14: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave()
 {
     parent::preSave();
     // Get the field's default values.
     $field_default_tags_value = $this->getFieldDefaults();
     $field_default_tags = unserialize($field_default_tags_value[0]['value']);
     // Get the value about to be saved.
     $current_value = $this->value;
     $current_tags = unserialize($current_value);
     // Only include values that differ from the default.
     // @TODO: When site defaults are added, account for those.
     $tags_to_save = array();
     foreach ($current_tags as $tag_id => $tag_value) {
         if ($tag_value != $field_default_tags[$tag_id]) {
             $tags_to_save[$tag_id] = $tag_value;
         }
     }
     // Update the value to only save overridden tags.
     $this->value = serialize($tags_to_save);
 }
開發者ID:dmyerson,項目名稱:d8ecs,代碼行數:23,代碼來源:MetatagFieldItem.php

示例15: 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


注:本文中的Drupal\Core\Field\FieldItemBase類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。