php Drupal-Core-TypedData-DataDefinition类(方法)实例源码

下面列出了php Drupal-Core-TypedData-DataDefinition 类(方法)源码代码实例,从而了解它的用法。

作者:darrylr    项目:protovbmwm   
/**
  * 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;
 }

作者:eigento    项目:tommiblo   
/**
  * {@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;
 }

作者:nstiela    项目:drops-   
/**
  * {@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;
 }

作者:nsp1    项目:Drupal   
/**
  * {@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;
 }

作者:lokeok    项目:d8intrane   
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;
 }

作者:aWEBoLab    项目:tax   
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;
 }

作者:heykarthikwith    项目:d8_custom_fiel   
/**
  * {@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;
 }

作者:anatalsce    项目:en-class   
/**
  * {@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;
 }

作者:eigento    项目:tommiblo   
/**
  * {@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;
 }

作者:nstiela    项目:drops-   
/**
  * 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.');
 }

作者:mglama    项目:drupalcamp-bas   
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;
 }

作者:DrupalCamp-NY    项目:dcnyc1   
/**
  * {@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;
 }

作者:pjonckier    项目:addthi   
/**
  * {@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;
 }

作者:alnutil    项目:drunatr   
/**
  * {@inheritdoc}
  */
 public function getPropertyDefinitions()
 {
     if (!isset(static::$propertyDefinitions)) {
         static::$propertyDefinitions['value'] = DataDefinition::create('map')->setLabel(t('Serialized value'));
     }
     return static::$propertyDefinitions;
 }

作者:novaFT    项目:quiz-drupal   
/**
  * {@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;
 }

作者:vinodpanicke    项目:drupal-under-the-hoo   
/**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     $properties = parent::propertyDefinitions($field_definition);
     $properties['display'] = DataDefinition::create('boolean')->setLabel(t('Display'))->setDescription(t('Flag to control whether this file should be displayed when viewing content'));
     $properties['description'] = DataDefinition::create('string')->setLabel(t('Description'));
     return $properties;
 }

作者:eloi    项目:botafoc.ca   
/**
   * {@inheritdoc}
   */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties['value'] = DataDefinition::create('string')
      ->setLabel(t('Text value'))
      ->addConstraint('Length', array('max' => 255))
      ->setRequired(TRUE);

    return $properties;
  }

作者:justincletu    项目:webdrupalpr   
/**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     $properties = [];
     $properties['csv'] = DataDefinition::create('string')->setLabel(t('CSV'));
     $properties['csv_url'] = DataDefinition::create('string')->setLabel(t('CSV URL'));
     $properties['config'] = DataDefinition::create('string')->setLabel(t('Config'));
     return $properties;
 }

作者:eigento    项目:tommiblo   
/**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     $properties['value'] = DataDefinition::create('datetime_iso8601')->setLabel(t('Start date value'))->setRequired(TRUE);
     $properties['start_date'] = DataDefinition::create('any')->setLabel(t('Computed start date'))->setDescription(t('The computed start DateTime object.'))->setComputed(TRUE)->setClass(DateTimeComputed::class)->setSetting('date source', 'value');
     $properties['end_value'] = DataDefinition::create('datetime_iso8601')->setLabel(t('End date value'))->setRequired(TRUE);
     $properties['end_date'] = DataDefinition::create('any')->setLabel(t('Computed end date'))->setDescription(t('The computed end DateTime object.'))->setComputed(TRUE)->setClass(DateTimeComputed::class)->setSetting('date source', 'end_value');
     return $properties;
 }

作者:mglama    项目:panelizer-d8-prototyp   
/**
  * {@inheritdoc}
  */
 public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition)
 {
     // Prevent early t() calls by using the TranslatableMarkup.
     $properties['view_mode'] = DataDefinition::create('string')->setLabel(new TranslatableMarkup('View mode'))->setSetting('case_sensitive', FALSE)->setRequired(TRUE);
     $properties['default'] = DataDefinition::create('string')->setLabel(new TranslatableMarkup('Default name'))->setSetting('case_sensitive', FALSE)->setRequired(FALSE);
     $properties['panels_display'] = MapDataDefinition::create('map')->setLabel(new TranslatableMarkup('Panels display'))->setRequired(TRUE);
     return $properties;
 }


问题


面经


文章

微信
公众号

扫码关注公众号