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


PHP DataDefinition::create方法代码示例

本文整理汇总了PHP中Drupal\Core\TypedData\DataDefinition::create方法的典型用法代码示例。如果您正苦于以下问题:PHP DataDefinition::create方法的具体用法?PHP DataDefinition::create怎么用?PHP DataDefinition::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\TypedData\DataDefinition的用法示例。


在下文中一共展示了DataDefinition::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: propertyDefinitionsByType

 /**
  * Helper function. Returns field properties based on the given type.
  *
  * @param string $type
  *   Range field data type. Either 'integer', 'float' or 'string'.
  *
  * @return \Drupal\Core\TypedData\DataDefinitionInterface[]
  *   An array of property definitions of contained properties, keyed by
  *   property name.
  */
 protected static function propertyDefinitionsByType($type)
 {
     $properties = array();
     $properties['from'] = DataDefinition::create($type)->setLabel(t('From value'))->setRequired(TRUE);
     $properties['to'] = DataDefinition::create($type)->setLabel(t('To value'))->setRequired(TRUE);
     return $properties;
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:17,代码来源:RangeItemBase.php

示例2: propertyDefinitions

 /**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     $properties['value'] = DataDefinition::create('string')->setLabel(new TranslatableMarkup('The hashed password'))->setSetting('case_sensitive', TRUE);
     $properties['existing'] = DataDefinition::create('string')->setLabel(new TranslatableMarkup('Existing password'));
     $properties['pre_hashed'] = DataDefinition::create('boolean')->setLabel(new TranslatableMarkup('Determines if a password needs hashing'));
     return $properties;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:10,代码来源:PasswordItem.php

示例3: propertyDefinitions

 /**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     $properties['value'] = DataDefinition::create('string')->setLabel(t('Text'))->setRequired(TRUE);
     $properties['format'] = DataDefinition::create('filter_format')->setLabel(t('Text format'));
     $properties['processed'] = DataDefinition::create('string')->setLabel(t('Processed text'))->setDescription(t('The text with the text format applied.'))->setComputed(TRUE)->setClass('\\Drupal\\text\\TextProcessed')->setSetting('text source', 'value');
     return $properties;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:10,代码来源:TextItemBase.php

示例4: propertyDefinitions

 /**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     $settings = $field_definition->getSettings();
     $target_type_info = \Drupal::entityManager()->getDefinition($settings['target_type']);
     $target_id_data_type = 'string';
     if ($target_type_info->isSubclassOf('\\Drupal\\Core\\Entity\\FieldableEntityInterface')) {
         $id_definition = \Drupal::entityManager()->getBaseFieldDefinitions($settings['target_type'])[$target_type_info->getKey('id')];
         if ($id_definition->getType() === 'integer') {
             $target_id_data_type = 'integer';
         }
     }
     if ($target_id_data_type === 'integer') {
         $target_id_definition = DataDefinition::create('integer')->setLabel(t('@label ID', array($target_type_info->getLabel())))->setSetting('unsigned', TRUE);
     } else {
         $target_id_definition = DataDefinition::create('string')->setLabel(t('@label ID', array($target_type_info->getLabel())));
     }
     $target_id_definition->setRequired(TRUE);
     $properties['target_id'] = $target_id_definition;
     $properties['entity'] = DataReferenceDefinition::create('entity')->setLabel($target_type_info->getLabel())->setDescription(t('The referenced entity'))->setComputed(TRUE)->setReadOnly(FALSE)->setTargetDefinition(EntityDataDefinition::create($settings['target_type']))->addConstraint('EntityType', $settings['target_type']);
     if (isset($settings['target_bundle'])) {
         $properties['entity']->addConstraint('Bundle', $settings['target_bundle']);
         // Set any further bundle constraints on the target definition as well,
         // such that it can derive more special data types if possible. For
         // example, "entity:node:page" instead of "entity:node".
         $properties['entity']->getTargetDefinition()->addConstraint('Bundle', $settings['target_bundle']);
     }
     return $properties;
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:31,代码来源:EntityReferenceItem.php

示例5: propertyDefinitions

 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     $properties['away_from'] = DataDefinition::create('integer')->setLabel(t('Away from'));
     $properties['away_to'] = DataDefinition::create('integer')->setLabel(t('Away to'));
     $properties['away_time'] = DataDefinition::create('integer')->setLabel(t('Away time'));
     return $properties;
 }
开发者ID:lokeoke,项目名称:d8intranet,代码行数:7,代码来源:AwayRangeItem.php

示例6: provideTestValidate

 public function provideTestValidate()
 {
     $data = [];
     $data[] = [new BooleanData(DataDefinition::create('boolean')), NULL, TRUE];
     $data[] = [new BooleanData(DataDefinition::create('boolean')), 1, TRUE];
     $data[] = [new BooleanData(DataDefinition::create('boolean')), 'test', FALSE];
     $data[] = [new FloatData(DataDefinition::create('float')), 1.5, TRUE];
     $data[] = [new FloatData(DataDefinition::create('float')), 'test', FALSE];
     $data[] = [new IntegerData(DataDefinition::create('integer')), 1, TRUE];
     $data[] = [new IntegerData(DataDefinition::create('integer')), 1.5, FALSE];
     $data[] = [new IntegerData(DataDefinition::create('integer')), 'test', FALSE];
     $data[] = [new StringData(DataDefinition::create('string')), 'test', TRUE];
     $data[] = [new StringData(DataDefinition::create('string')), new TranslatableMarkup('test'), TRUE];
     // It is odd that 1 is a valid string.
     // $data[] = [$this->getMock('Drupal\Core\TypedData\Type\StringInterface'), 1, FALSE];
     $data[] = [new StringData(DataDefinition::create('string')), [], FALSE];
     $data[] = [new Uri(DataDefinition::create('uri')), 'http://www.drupal.org', TRUE];
     $data[] = [new Uri(DataDefinition::create('uri')), 'https://www.drupal.org', TRUE];
     $data[] = [new Uri(DataDefinition::create('uri')), 'Invalid', FALSE];
     $data[] = [new Uri(DataDefinition::create('uri')), 'entity:node/1', TRUE];
     $data[] = [new Uri(DataDefinition::create('uri')), 'base:', TRUE];
     $data[] = [new Uri(DataDefinition::create('uri')), 'base:node', TRUE];
     $data[] = [new Uri(DataDefinition::create('uri')), 'internal:', TRUE];
     $data[] = [new Uri(DataDefinition::create('uri')), 'public://', FALSE];
     $data[] = [new Uri(DataDefinition::create('uri')), 'public://foo.png', TRUE];
     $data[] = [new Uri(DataDefinition::create('uri')), 'private://', FALSE];
     $data[] = [new Uri(DataDefinition::create('uri')), 'private://foo.png', TRUE];
     $data[] = [new Uri(DataDefinition::create('uri')), 'drupal.org', FALSE];
     return $data;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:30,代码来源:PrimitiveTypeConstraintValidatorTest.php

示例7: propertyDefinitions

 /**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     $properties['source_description'] = DataDefinition::create('string')->setLabel(t('Snippet description'));
     $properties['source_code'] = DataDefinition::create('string')->setLabel(t('Snippet code'));
     $properties['source_lang'] = DataDefinition::create('string')->setLabel(t('Last comment timestamp'))->setDescription(t('Snippet code language'));
     return $properties;
 }
开发者ID:heykarthikwithu,项目名称:d8_custom_field,代码行数:10,代码来源:CustomFieldItem.php

示例8: propertyDefinitions

 /**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     $properties = parent::propertyDefinitions($field_definition);
     $properties['summary'] = DataDefinition::create('string')->setLabel(t('Summary text value'));
     $properties['summary_processed'] = DataDefinition::create('string')->setLabel(t('Processed summary text'))->setDescription(t('The summary text value with the text format applied.'))->setComputed(TRUE)->setClass('\\Drupal\\text\\TextProcessed')->setSetting('text source', 'summary');
     return $properties;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:10,代码来源:TextWithSummaryItem.php

示例9: propertyDefinitions

 /**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     // This is called very early by the user entity roles field. Prevent
     // early t() calls by using the TranslatableMarkup.
     $properties['value'] = DataDefinition::create('string')->setLabel(new TranslatableMarkup('Text value'))->setSetting('case_sensitive', $field_definition->getSetting('case_sensitive'))->setRequired(TRUE);
     return $properties;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:10,代码来源:StringItemBase.php

示例10: testValidation

 /**
  * Tests the ComplexData validation constraint validator.
  *
  * For testing a map including a constraint on one of its keys is defined.
  */
 public function testValidation()
 {
     // Create a definition that specifies some ComplexData constraint.
     $definition = MapDataDefinition::create()->setPropertyDefinition('key', DataDefinition::create('integer'))->addConstraint('ComplexData', array('key' => array('AllowedValues' => array(1, 2, 3))));
     // Test the validation.
     $typed_data = $this->typedData->create($definition, array('key' => 1));
     $violations = $typed_data->validate();
     $this->assertEqual($violations->count(), 0, 'Validation passed for correct value.');
     // Test the validation when an invalid value is passed.
     $typed_data = $this->typedData->create($definition, array('key' => 4));
     $violations = $typed_data->validate();
     $this->assertEqual($violations->count(), 1, 'Validation failed for incorrect value.');
     // Make sure the information provided by a violation is correct.
     $violation = $violations[0];
     $this->assertEqual($violation->getMessage(), t('The value you selected is not a valid choice.'), 'The message for invalid value is correct.');
     $this->assertEqual($violation->getRoot(), $typed_data, 'Violation root is correct.');
     $this->assertEqual($violation->getInvalidValue(), 4, 'The invalid value is set correctly in the violation.');
     // Test using the constraint with a map without the specified key. This
     // should be ignored as long as there is no NotNull or NotBlank constraint.
     $typed_data = $this->typedData->create($definition, array('foo' => 'bar'));
     $violations = $typed_data->validate();
     $this->assertEqual($violations->count(), 0, 'Constraint on non-existing key is ignored.');
     $definition = MapDataDefinition::create()->setPropertyDefinition('key', DataDefinition::create('integer'))->addConstraint('ComplexData', array('key' => array('NotNull' => array())));
     $typed_data = $this->typedData->create($definition, array('foo' => 'bar'));
     $violations = $typed_data->validate();
     $this->assertEqual($violations->count(), 1, 'Key is required.');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:32,代码来源:ComplexDataConstraintValidatorTest.php

示例11: propertyDefinitions

 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     $properties = parent::propertyDefinitions($field_definition);
     $properties[';value'] = DataDefinition::create('datetime_iso8601')->setLabel(t('Date value'))->setRequired(TRUE);
     $properties['date'] = DataDefinition::create('any')->setLabel(t('Computed date'))->setDescription(t('The computed DateTime object.'))->setComputed(TRUE)->setClass('\\Drupal\\datetime\\DateTimeComputed')->setSetting('date source', 'value');
     return $properties;
 }
开发者ID:mglaman,项目名称:drupalcamp-base,代码行数:7,代码来源:ScheduleSessionItem.php

示例12: propertyDefinitions

 /**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     $properties['uri'] = DataDefinition::create('uri')->setLabel(t('URI'));
     $properties['title'] = DataDefinition::create('string')->setLabel(t('Link text'));
     $properties['options'] = MapDataDefinition::create()->setLabel(t('Options'));
     return $properties;
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:10,代码来源:LinkItem.php

示例13: propertyDefinitions

 /**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     // This is called very early by the user entity roles field. Prevent
     // early t() calls by using the TranslationWrapper.
     $properties['value'] = DataDefinition::create('string')->setLabel(new TranslationWrapper('Text value'));
     return $properties;
 }
开发者ID:pjonckiere,项目名称:addthis,代码行数:10,代码来源:AddThisItem.php

示例14: getPropertyDefinitions

 /**
  * {@inheritdoc}
  */
 public function getPropertyDefinitions()
 {
     if (!isset(static::$propertyDefinitions)) {
         static::$propertyDefinitions['value'] = DataDefinition::create('map')->setLabel(t('Serialized value'));
     }
     return static::$propertyDefinitions;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:10,代码来源:SerializedItem.php

示例15: propertyDefinitions

 /**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     // Prevent early t() calls by using the TranslatableMarkup.
     $properties['name'] = DataDefinition::create('string')->setLabel(new TranslatableMarkup('Text'))->setRequired(FALSE);
     $properties['value'] = DataDefinition::create('integer')->setLabel(new TranslatableMarkup('Value'))->setRequired(FALSE);
     return $properties;
 }
开发者ID:novaFTL,项目名称:quiz-drupal8,代码行数:10,代码来源:MultipleChoice.php


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