예제 #1
0
 /**
  * Tests using entity fields of the field field type.
  */
 public function testTestItem()
 {
     // Verify entity creation.
     $entity = entity_create('entity_test');
     $value = rand(1, 10);
     $entity->field_test = $value;
     $entity->name->value = $this->randomName();
     $entity->save();
     // Verify entity has been created properly.
     $id = $entity->id();
     $entity = entity_load('entity_test', $id);
     $this->assertTrue($entity->{$this->field_name} instanceof FieldItemListInterface, 'Field implements interface.');
     $this->assertTrue($entity->{$this->field_name}[0] instanceof FieldItemInterface, 'Field item implements interface.');
     $this->assertEqual($entity->{$this->field_name}->value, $value);
     $this->assertEqual($entity->{$this->field_name}[0]->value, $value);
     // Verify changing the field value.
     $new_value = rand(1, 10);
     $entity->field_test->value = $new_value;
     $this->assertEqual($entity->{$this->field_name}->value, $new_value);
     // Read changed entity and assert changed values.
     $entity->save();
     $entity = entity_load('entity_test', $id);
     $this->assertEqual($entity->{$this->field_name}->value, $new_value);
     // Test the schema for this field type.
     $expected_schema = array('columns' => array('value' => array('type' => 'int', 'size' => 'medium', 'not null' => FALSE)), 'unique keys' => array(), 'indexes' => array('value' => array('value')), 'foreign keys' => array());
     $field_schema = FieldDefinition::create('test_field')->getSchema();
     $this->assertEqual($field_schema, $expected_schema);
 }
 /**
  * Tests deriving metadata about fields.
  */
 public function testFields()
 {
     $field_definition = FieldDefinition::create('integer');
     // Fields are lists of complex data.
     $this->assertTrue($field_definition instanceof ListDataDefinitionInterface);
     $this->assertFalse($field_definition instanceof ComplexDataDefinitionInterface);
     $field_item_definition = $field_definition->getItemDefinition();
     $this->assertFalse($field_item_definition instanceof ListDataDefinitionInterface);
     $this->assertTrue($field_item_definition instanceof ComplexDataDefinitionInterface);
     // Derive metadata about field item properties.
     $this->assertEqual(array_keys($field_item_definition->getPropertyDefinitions()), array('value'));
     $this->assertEqual($field_item_definition->getPropertyDefinition('value')->getDataType(), 'integer');
     $this->assertEqual($field_item_definition->getMainPropertyName(), 'value');
     $this->assertNull($field_item_definition->getPropertyDefinition('invalid'));
     // Test accessing field item property metadata via the field definition.
     $this->assertTrue($field_definition instanceof FieldDefinitionInterface);
     $this->assertEqual(array_keys($field_definition->getPropertyDefinitions()), array('value'));
     $this->assertEqual($field_definition->getPropertyDefinition('value')->getDataType(), 'integer');
     $this->assertEqual($field_definition->getMainPropertyName(), 'value');
     $this->assertNull($field_definition->getPropertyDefinition('invalid'));
     // Test using the definition factory for field item lists and field items.
     $field_item = $this->typedDataManager->createDataDefinition('field_item:integer');
     $this->assertFalse($field_item instanceof ListDataDefinitionInterface);
     $this->assertTrue($field_item instanceof ComplexDataDefinitionInterface);
     // Comparison should ignore the internal static cache, so compare the
     // serialized objects instead.
     $this->assertEqual(serialize($field_item_definition), serialize($field_item));
     $field_definition2 = $this->typedDataManager->createListDataDefinition('field_item:integer');
     $this->assertTrue($field_definition2 instanceof ListDataDefinitionInterface);
     $this->assertFalse($field_definition2 instanceof ComplexDataDefinitionInterface);
     $this->assertEqual(serialize($field_definition), serialize($field_definition2));
 }
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = parent::baseFieldDefinitions($entity_type);
     $fields['test_no_display'] = FieldDefinition::create('text')->setLabel(t('Field with no display'));
     $fields['test_display_configurable'] = FieldDefinition::create('text')->setLabel(t('Field with configurable display'))->setDisplayOptions('view', array('type' => 'text_default', 'weight' => 10))->setDisplayConfigurable('view', TRUE)->setDisplayOptions('form', array('type' => 'text_textfield', 'weight' => 10))->setDisplayConfigurable('form', TRUE);
     $fields['test_display_non_configurable'] = FieldDefinition::create('text')->setLabel(t('Field with non-configurable display'))->setDisplayOptions('view', array('type' => 'text_default', 'weight' => 11))->setDisplayOptions('form', array('type' => 'text_textfield', 'weight' => 11));
     return $fields;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = parent::baseFieldDefinitions($entity_type);
     $fields['revision_id'] = FieldDefinition::create('integer')->setLabel(t('Revision ID'))->setDescription(t('The version id of the test entity.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['langcode']->setRevisionable(TRUE);
     $fields['name']->setRevisionable(TRUE);
     $fields['user_id']->setRevisionable(TRUE);
     return $fields;
 }
 /**
  * {@inheritdoc}
  */
 public static function createFromDataType($data_type)
 {
     // The data type of a field item is in the form of "field_item:$field_type".
     $parts = explode(':', $data_type, 2);
     if ($parts[0] != 'field_item') {
         throw new \InvalidArgumentException('Data type must be in the form of "field_item:FIELD_TYPE".');
     }
     $field_definition = FieldDefinition::create($parts[1]);
     return $field_definition->getItemDefinition();
 }
예제 #6
0
파일: FooBar.php 프로젝트: bnchdrff/foo_bar
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['fbid'] = FieldDefinition::create('integer')->setLabel(t('ID'))->setDescription(t('The ID of the FooBar entity.'))->setReadOnly(TRUE);
     $fields['uuid'] = FieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The UUID of the FooBar entity.'))->setReadOnly(TRUE);
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The language code of theFooBar entity.'));
     $fields['name'] = FieldDefinition::create('string')->setLabel(t('Name'))->setDescription(t('The name of the FooBar entity.'))->setTranslatable(TRUE)->setPropertyConstraints('value', array('Length' => array('max' => 32)))->setSettings(array('default_value' => '', 'max_length' => 255, 'text_processing' => 0))->setDisplayOptions('view', array('label' => 'above', 'type' => 'string', 'weight' => -6))->setDisplayOptions('form', array('type' => 'string', 'weight' => -6))->setDisplayConfigurable('form', TRUE)->setDisplayConfigurable('view', TRUE);
     $fields['type'] = FieldDefinition::create('string')->setLabel(t('Type'))->setDescription(t('The bundle of the FooBar entity.'))->setRequired(TRUE);
     $fields['user_id'] = FieldDefinition::create('entity_reference')->setLabel(t('User ID'))->setDescription(t('The ID of the associated user.'))->setSettings(array('target_type' => 'user'))->setTranslatable(TRUE);
     $fields['foo_bar_field'] = FieldDefinition::create('string')->setLabel(t('First FooBar Field'))->setDescription(t('One field of the FooBar entity.'))->setTranslatable(TRUE)->setPropertyConstraints('value', array('Length' => array('max' => 32)))->setSettings(array('default_value' => '', 'max_length' => 255, 'text_processing' => 0))->setDisplayOptions('view', array('label' => 'above', 'type' => 'string', 'weight' => -5))->setDisplayOptions('form', array('type' => 'string', 'weight' => -5))->setDisplayConfigurable('form', TRUE)->setDisplayConfigurable('view', TRUE);
     return $fields;
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['id'] = FieldDefinition::create('integer')->setLabel(t('ID'))->setDescription(t('The ID of the test entity.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['uuid'] = FieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The UUID of the test entity.'))->setReadOnly(TRUE);
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The language code of the test entity.'));
     $fields['name'] = FieldDefinition::create('string')->setLabel(t('Name'))->setDescription(t('The name of the test entity.'))->setTranslatable(TRUE)->setSetting('max_length', 32)->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'string', 'weight' => -5));
     // @todo: Add allowed values validation.
     $fields['type'] = FieldDefinition::create('string')->setLabel(t('Type'))->setDescription(t('The bundle of the test entity.'))->setRequired(TRUE);
     $fields['user_id'] = FieldDefinition::create('entity_reference')->setLabel(t('User ID'))->setDescription(t('The ID of the associated user.'))->setSettings(array('target_type' => 'user'))->setTranslatable(TRUE);
     return $fields;
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['iid'] = FieldDefinition::create('integer')->setLabel(t('Aggregator item ID'))->setDescription(t('The ID of the feed item.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['fid'] = FieldDefinition::create('entity_reference')->setLabel(t('Aggregator feed ID'))->setDescription(t('The ID of the aggregator feed.'))->setSetting('target_type', 'aggregator_feed');
     $fields['title'] = FieldDefinition::create('string')->setLabel(t('Title'))->setDescription(t('The title of the feed item.'));
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The feed item language code.'));
     $fields['link'] = FieldDefinition::create('uri')->setLabel(t('Link'))->setDescription(t('The link of the feed item.'));
     $fields['author'] = FieldDefinition::create('string')->setLabel(t('Author'))->setDescription(t('The author of the feed item.'));
     $fields['description'] = FieldDefinition::create('string_long')->setLabel(t('Description'))->setDescription(t('The body of the feed item.'));
     $fields['timestamp'] = FieldDefinition::create('created')->setLabel(t('Posted timestamp'))->setDescription(t('Posted date of the feed item, as a Unix timestamp.'));
     // @todo Convert to a real UUID field in https://drupal.org/node/2149851.
     $fields['guid'] = FieldDefinition::create('string_long')->setLabel(t('GUID'))->setDescription(t('Unique identifier for the feed item.'));
     return $fields;
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     // getModuleAndPath() returns an array of the module name and directory.
     list($module_name, $module_dir) = $this->getModuleAndPath();
     $namespaces = new \ArrayObject();
     $namespaces["Drupal\\{$module_name}"] = $module_dir . '/src';
     $module_handler = $this->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
     $module_handler->expects($this->once())->method('moduleExists')->with($module_name)->will($this->returnValue(TRUE));
     $plugin_manager = new FieldTypePluginManager($namespaces, $this->getMock('Drupal\\Core\\Cache\\CacheBackendInterface'), $module_handler);
     $container = new ContainerBuilder();
     $container->set('plugin.manager.field.field_type', $plugin_manager);
     // The 'string_translation' service is used by the @Translation annotation.
     $container->set('string_translation', $this->getStringTranslationStub());
     \Drupal::setContainer($container);
     $this->definition = FieldDefinition::create($this->getPluginId());
 }
예제 #10
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['id'] = FieldDefinition::create('integer')->setLabel(t('Custom block ID'))->setDescription(t('The custom block ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['uuid'] = FieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The custom block UUID.'))->setReadOnly(TRUE);
     $fields['revision_id'] = FieldDefinition::create('integer')->setLabel(t('Revision ID'))->setDescription(t('The revision ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The custom block language code.'))->setRevisionable(TRUE);
     $fields['info'] = FieldDefinition::create('string')->setLabel(t('Block description'))->setDescription(t('A brief description of your block.'))->setRevisionable(TRUE)->setTranslatable(TRUE)->setRequired(TRUE)->setDisplayOptions('form', array('type' => 'string', 'weight' => -5))->setDisplayConfigurable('form', TRUE);
     $fields['type'] = FieldDefinition::create('entity_reference')->setLabel(t('Block type'))->setDescription(t('The block type.'))->setSetting('target_type', 'block_content_type');
     $fields['revision_log'] = FieldDefinition::create('string_long')->setLabel(t('Revision log message'))->setDescription(t('The log entry explaining the changes in this revision.'))->setRevisionable(TRUE);
     $fields['changed'] = FieldDefinition::create('changed')->setLabel(t('Changed'))->setDescription(t('The time that the custom block was last edited.'))->setRevisionable(TRUE);
     return $fields;
 }
예제 #11
0
 /**
  * Tests typed data validation.
  */
 public function testTypedDataValidation()
 {
     $definition = DataDefinition::create('integer')->setConstraints(array('Range' => array('min' => 5)));
     $violations = $this->typedDataManager->create($definition, 10)->validate();
     $this->assertEqual($violations->count(), 0);
     $integer = $this->typedDataManager->create($definition, 1);
     $violations = $integer->validate();
     $this->assertEqual($violations->count(), 1);
     // Test translating violation messages.
     $message = t('This value should be %limit or more.', array('%limit' => 5));
     $this->assertEqual($violations[0]->getMessage(), $message, 'Translated violation message retrieved.');
     $this->assertEqual($violations[0]->getPropertyPath(), '');
     $this->assertIdentical($violations[0]->getRoot(), $integer, 'Root object returned.');
     // Test translating violation messages when pluralization is used.
     $definition = DataDefinition::create('string')->setConstraints(array('Length' => array('min' => 10)));
     $violations = $this->typedDataManager->create($definition, "short")->validate();
     $this->assertEqual($violations->count(), 1);
     $message = t('This value is too short. It should have %limit characters or more.', array('%limit' => 10));
     $this->assertEqual($violations[0]->getMessage(), $message, 'Translated violation message retrieved.');
     // Test having multiple violations.
     $definition = DataDefinition::create('integer')->setConstraints(array('Range' => array('min' => 5), 'Null' => array()));
     $violations = $this->typedDataManager->create($definition, 10)->validate();
     $this->assertEqual($violations->count(), 1);
     $violations = $this->typedDataManager->create($definition, 1)->validate();
     $this->assertEqual($violations->count(), 2);
     // Test validating property containers and make sure the NotNull and Null
     // constraints work with typed data containers.
     $definition = FieldDefinition::create('integer')->setConstraints(array('NotNull' => array()));
     $field_item = $this->typedDataManager->create($definition, array('value' => 10));
     $violations = $field_item->validate();
     $this->assertEqual($violations->count(), 0);
     $field_item = $this->typedDataManager->create($definition, array('value' => 'no integer'));
     $violations = $field_item->validate();
     $this->assertEqual($violations->count(), 1);
     $this->assertEqual($violations[0]->getPropertyPath(), '0.value');
     // Test that the field item may not be empty.
     $field_item = $this->typedDataManager->create($definition);
     $violations = $field_item->validate();
     $this->assertEqual($violations->count(), 1);
     // Test the Null constraint with typed data containers.
     $definition = FieldDefinition::create('float')->setConstraints(array('Null' => array()));
     $field_item = $this->typedDataManager->create($definition, array('value' => 11.5));
     $violations = $field_item->validate();
     $this->assertEqual($violations->count(), 1);
     $field_item = $this->typedDataManager->create($definition);
     $violations = $field_item->validate();
     $this->assertEqual($violations->count(), 0);
     // Test getting constraint definitions by type.
     $definitions = $this->typedDataManager->getValidationConstraintManager()->getDefinitionsByType('entity');
     $this->assertTrue(isset($definitions['EntityType']), 'Constraint plugin found for type entity.');
     $this->assertTrue(isset($definitions['Null']), 'Constraint plugin found for type entity.');
     $this->assertTrue(isset($definitions['NotNull']), 'Constraint plugin found for type entity.');
     $definitions = $this->typedDataManager->getValidationConstraintManager()->getDefinitionsByType('string');
     $this->assertFalse(isset($definitions['EntityType']), 'Constraint plugin not found for type string.');
     $this->assertTrue(isset($definitions['Null']), 'Constraint plugin found for type string.');
     $this->assertTrue(isset($definitions['NotNull']), 'Constraint plugin found for type string.');
     // Test automatic 'required' validation.
     $definition = DataDefinition::create('integer')->setRequired(TRUE);
     $violations = $this->typedDataManager->create($definition)->validate();
     $this->assertEqual($violations->count(), 1);
     $violations = $this->typedDataManager->create($definition, 0)->validate();
     $this->assertEqual($violations->count(), 0);
     // Test validating a list of a values and make sure property paths starting
     // with "0" are created.
     $definition = FieldDefinition::create('integer');
     $violations = $this->typedDataManager->create($definition, array(array('value' => 10)))->validate();
     $this->assertEqual($violations->count(), 0);
     $violations = $this->typedDataManager->create($definition, array(array('value' => 'string')))->validate();
     $this->assertEqual($violations->count(), 1);
     $this->assertEqual($violations[0]->getInvalidValue(), 'string');
     $this->assertIdentical($violations[0]->getPropertyPath(), '0.value');
 }
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['tid'] = FieldDefinition::create('integer')->setLabel(t('Term ID'))->setDescription(t('The term ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['uuid'] = FieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The term UUID.'))->setReadOnly(TRUE);
     $fields['vid'] = FieldDefinition::create('entity_reference')->setLabel(t('Vocabulary'))->setDescription(t('The vocabulary to which the term is assigned.'))->setSetting('target_type', 'taxonomy_vocabulary');
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The term language code.'));
     $fields['name'] = FieldDefinition::create('string')->setLabel(t('Name'))->setDescription(t('The term name.'))->setTranslatable(TRUE)->setRequired(TRUE)->setSetting('max_length', 255)->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'string', 'weight' => -5))->setDisplayOptions('form', array('type' => 'string', 'weight' => -5))->setDisplayConfigurable('form', TRUE);
     $fields['description'] = FieldDefinition::create('text_long')->setLabel(t('Description'))->setDescription(t('A description of the term.'))->setTranslatable(TRUE)->setSetting('text_processing', 1)->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'text_default', 'weight' => 0))->setDisplayConfigurable('view', TRUE)->setDisplayOptions('form', array('type' => 'text_textfield', 'weight' => 0))->setDisplayConfigurable('form', TRUE);
     $fields['weight'] = FieldDefinition::create('integer')->setLabel(t('Weight'))->setDescription(t('The weight of this term in relation to other terms.'))->setDefaultValue(0);
     // @todo Convert this to an entity_reference field, see
     // https://drupal.org/node/1915056
     $fields['parent'] = FieldDefinition::create('integer')->setLabel(t('Term Parents'))->setDescription(t('The parents of this term.'))->setCardinality(FieldDefinition::CARDINALITY_UNLIMITED)->setDefaultValue(0)->setSetting('unsigned', TRUE)->addConstraint('TermParent', array());
     $fields['changed'] = FieldDefinition::create('changed')->setLabel(t('Changed'))->setDescription(t('The time that the term was last edited.'));
     return $fields;
 }
예제 #13
0
파일: Field.php 프로젝트: alnutile/drunatra
 /**
  * Gets the field definition.
  *
  * @return \Drupal\Core\Field\FieldDefinitionInterface
  *   The field definition used by this handler.
  */
 protected function getFieldDefinition()
 {
     if (!$this->fieldDefinition) {
         $field_storage_config = $this->getFieldStorageConfig();
         $this->fieldDefinition = FieldDefinition::createFromFieldStorageDefinition($field_storage_config);
     }
     return $this->fieldDefinition;
 }
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = parent::baseFieldDefinitions($entity_type);
     $fields['description'] = FieldDefinition::create('string')->setLabel(t('Some custom description'))->setDefaultValueCallback('entity_test_field_default_value');
     return $fields;
 }
예제 #15
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['fid'] = FieldDefinition::create('integer')->setLabel(t('File ID'))->setDescription(t('The file ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['uuid'] = FieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The file UUID.'))->setReadOnly(TRUE);
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The file language code.'));
     $fields['uid'] = FieldDefinition::create('entity_reference')->setLabel(t('User ID'))->setDescription(t('The user ID of the file.'))->setSetting('target_type', 'user');
     $fields['filename'] = FieldDefinition::create('string')->setLabel(t('Filename'))->setDescription(t('Name of the file with no path components.'));
     $fields['uri'] = FieldDefinition::create('uri')->setLabel(t('URI'))->setDescription(t('The URI to access the file (either local or remote).'))->setSetting('max_length', 255);
     $fields['filemime'] = FieldDefinition::create('string')->setLabel(t('File MIME type'))->setDescription(t("The file's MIME type."));
     $fields['filesize'] = FieldDefinition::create('integer')->setLabel(t('File size'))->setDescription(t('The size of the file in bytes.'))->setSetting('unsigned', TRUE)->setSetting('size', 'big');
     $fields['status'] = FieldDefinition::create('boolean')->setLabel(t('Status'))->setDescription(t('The status of the file, temporary (FALSE) and permanent (TRUE).'));
     $fields['created'] = FieldDefinition::create('created')->setLabel(t('Created'))->setDescription(t('The timestamp that the file was created.'));
     $fields['changed'] = FieldDefinition::create('changed')->setLabel(t('Changed'))->setDescription(t('The timestamp that the file was last changed.'));
     return $fields;
 }
예제 #16
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['id'] = FieldDefinition::create('integer')->setLabel(t('ID'))->setDescription(t('The ID of the shortcut.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['uuid'] = FieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The UUID of the shortcut.'))->setReadOnly(TRUE);
     $fields['shortcut_set'] = FieldDefinition::create('entity_reference')->setLabel(t('Shortcut set'))->setDescription(t('The bundle of the shortcut.'))->setSetting('target_type', 'shortcut_set')->setRequired(TRUE);
     $fields['title'] = FieldDefinition::create('string')->setLabel(t('Name'))->setDescription(t('The name of the shortcut.'))->setRequired(TRUE)->setTranslatable(TRUE)->setDefaultValue('')->setSetting('max_length', 255)->setDisplayOptions('form', array('type' => 'string', 'weight' => -10, 'settings' => array('size' => 40)));
     $fields['weight'] = FieldDefinition::create('integer')->setLabel(t('Weight'))->setDescription(t('Weight among shortcuts in the same shortcut set.'));
     $fields['route_name'] = FieldDefinition::create('string')->setLabel(t('Route name'))->setDescription(t('The machine name of a defined Route this shortcut represents.'));
     $fields['route_parameters'] = FieldDefinition::create('map')->setLabel(t('Route parameters'))->setDescription(t('A serialized array of route parameters of this shortcut.'));
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The language code of the shortcut.'));
     $fields['path'] = FieldDefinition::create('string')->setLabel(t('Path'))->setDescription(t('The computed shortcut path.'))->setComputed(TRUE)->setCustomStorage(TRUE);
     $item_definition = $fields['path']->getItemDefinition();
     $item_definition->setClass('\\Drupal\\shortcut\\ShortcutPathItem');
     $fields['path']->setItemDefinition($item_definition);
     return $fields;
 }
예제 #17
0
 /**
  * Tests custom storage.
  */
 public function testCustomStorage()
 {
     $definition = FieldDefinition::create($this->fieldType);
     $this->assertFalse($definition->hasCustomStorage());
     $definition->setCustomStorage(TRUE);
     $this->assertTrue($definition->hasCustomStorage());
     $definition->setCustomStorage(FALSE);
     $this->assertFalse($definition->hasCustomStorage());
 }
예제 #18
0
 /**
  * Tests validation constraints provided by the Entity API.
  */
 public function testEntityConstraintValidation()
 {
     $entity = $this->createTestEntity('entity_test');
     $entity->save();
     // Create a reference field item and let it reference the entity.
     $definition = FieldDefinition::create('entity_reference')->setLabel('Test entity')->setSetting('target_type', 'entity_test');
     $reference_field = \Drupal::typedDataManager()->create($definition);
     $reference = $reference_field->first()->get('entity');
     $reference->setValue($entity);
     // Test validation the typed data object.
     $violations = $reference->validate();
     $this->assertEqual($violations->count(), 0);
     // Test validating an entity of the wrong type.
     $user = $this->createUser();
     $user->save();
     $node = entity_create('node', array('type' => 'page', 'uid' => $user->id()));
     $reference->setValue($node);
     $violations = $reference->validate();
     $this->assertEqual($violations->count(), 1);
     // Test bundle validation.
     NodeType::create(array('type' => 'article'))->save();
     $definition = FieldDefinition::create('entity_reference')->setLabel('Test entity')->setSettings(array('target_type' => 'node', 'target_bundle' => 'article'));
     $reference_field = \Drupal::TypedDataManager()->create($definition);
     $reference = $reference_field->first()->get('entity');
     $reference->setValue($node);
     $violations = $reference->validate();
     $this->assertEqual($violations->count(), 1);
     $node = entity_create('node', array('type' => 'article', 'uid' => $user->id()));
     $node->save();
     $reference->setValue($node);
     $violations = $reference->validate();
     $this->assertEqual($violations->count(), 0);
 }
 /**
  * Tests field SQL schema generation for an entity with a string identifier.
  *
  * @covers ::_fieldSqlSchema()
  */
 public function testFieldSqlSchemaForEntityWithStringIdentifier()
 {
     $field_type_manager = $this->getMock('Drupal\\Core\\Field\\FieldTypePluginManagerInterface');
     $this->container->set('plugin.manager.field.field_type', $field_type_manager);
     $this->container->set('entity.manager', $this->entityManager);
     $this->entityType->expects($this->any())->method('getKey')->will($this->returnValueMap(array(array('id', 'id'), array('revision', 'revision'))));
     $this->entityType->expects($this->once())->method('hasKey')->with('revision')->will($this->returnValue(TRUE));
     $field_type_manager->expects($this->exactly(2))->method('getDefaultSettings')->will($this->returnValue(array()));
     $field_type_manager->expects($this->exactly(2))->method('getDefaultInstanceSettings')->will($this->returnValue(array()));
     $this->fieldDefinitions['id'] = FieldDefinition::create('string')->setName('id');
     $this->fieldDefinitions['revision'] = FieldDefinition::create('string')->setName('revision');
     $this->entityManager->expects($this->any())->method('getDefinition')->with('test_entity')->will($this->returnValue($this->entityType));
     $this->entityManager->expects($this->any())->method('getBaseFieldDefinitions')->will($this->returnValue($this->fieldDefinitions));
     // Define a field definition for a test_field field.
     $field_storage = $this->getMock('\\Drupal\\field\\FieldStorageConfigInterface');
     $field_storage->deleted = FALSE;
     $field_storage->expects($this->any())->method('getName')->will($this->returnValue('test_field'));
     $field_storage->expects($this->any())->method('getTargetEntityTypeId')->will($this->returnValue('test_entity'));
     $field_schema = array('columns' => array('value' => array('type' => 'varchar', 'length' => 10, 'not null' => FALSE)), 'unique keys' => array(), 'indexes' => array(), 'foreign keys' => array());
     $field_storage->expects($this->any())->method('getSchema')->will($this->returnValue($field_schema));
     $schema = ContentEntityDatabaseStorage::_fieldSqlSchema($field_storage);
     // Make sure that the entity_id schema field if of type varchar.
     $this->assertEquals($schema['test_entity__test_field']['fields']['entity_id']['type'], 'varchar');
     $this->assertEquals($schema['test_entity__test_field']['fields']['revision_id']['type'], 'varchar');
 }
예제 #20
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = parent::baseFieldDefinitions($entity_type);
     $fields['id'] = FieldDefinition::create('string')->setLabel(t('ID'))->setDescription(t('The ID of the test entity.'))->setReadOnly(TRUE);
     return $fields;
 }
예제 #21
0
 /**
  * Create schema from an id definition.
  *
  * @param array $id_definition
  *   A field schema definition. Can be SQL schema or a type data
  *   based schema. In the latter case, the value of type needs to be
  *   $typed_data_type.$column
  * @return array
  */
 protected function getFieldSchema(array $id_definition)
 {
     $type_parts = explode('.', $id_definition['type']);
     if (count($type_parts) == 1) {
         $type_parts[] = 'value';
     }
     $schema = FieldDefinition::create($type_parts[0])->getColumns();
     return $schema[$type_parts[1]];
 }
예제 #22
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['nid'] = FieldDefinition::create('integer')->setLabel(t('Node ID'))->setDescription(t('The node ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['uuid'] = FieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The node UUID.'))->setReadOnly(TRUE);
     $fields['vid'] = FieldDefinition::create('integer')->setLabel(t('Revision ID'))->setDescription(t('The node revision ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['type'] = FieldDefinition::create('entity_reference')->setLabel(t('Type'))->setDescription(t('The node type.'))->setSetting('target_type', 'node_type')->setReadOnly(TRUE);
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The node language code.'))->setRevisionable(TRUE);
     $fields['title'] = FieldDefinition::create('string')->setLabel(t('Title'))->setDescription(t('The title of this node, always treated as non-markup plain text.'))->setRequired(TRUE)->setTranslatable(TRUE)->setRevisionable(TRUE)->setDefaultValue('')->setSetting('max_length', 255)->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'string', 'weight' => -5))->setDisplayOptions('form', array('type' => 'string', 'weight' => -5))->setDisplayConfigurable('form', TRUE);
     $fields['uid'] = FieldDefinition::create('entity_reference')->setLabel(t('Author'))->setDescription(t('The user that is the node author.'))->setRevisionable(TRUE)->setSetting('target_type', 'user')->setTranslatable(TRUE);
     $fields['status'] = FieldDefinition::create('boolean')->setLabel(t('Publishing status'))->setDescription(t('A boolean indicating whether the node is published.'))->setRevisionable(TRUE)->setTranslatable(TRUE);
     $fields['created'] = FieldDefinition::create('created')->setLabel(t('Created'))->setDescription(t('The time that the node was created.'))->setRevisionable(TRUE)->setTranslatable(TRUE);
     $fields['changed'] = FieldDefinition::create('changed')->setLabel(t('Changed'))->setDescription(t('The time that the node was last edited.'))->setRevisionable(TRUE)->setTranslatable(TRUE);
     $fields['promote'] = FieldDefinition::create('boolean')->setLabel(t('Promote'))->setDescription(t('A boolean indicating whether the node should be displayed on the front page.'))->setRevisionable(TRUE)->setTranslatable(TRUE);
     $fields['sticky'] = FieldDefinition::create('boolean')->setLabel(t('Sticky'))->setDescription(t('A boolean indicating whether the node should be displayed at the top of lists in which it appears.'))->setRevisionable(TRUE)->setTranslatable(TRUE);
     $fields['revision_timestamp'] = FieldDefinition::create('created')->setLabel(t('Revision timestamp'))->setDescription(t('The time that the current revision was created.'))->setQueryable(FALSE)->setRevisionable(TRUE);
     $fields['revision_uid'] = FieldDefinition::create('entity_reference')->setLabel(t('Revision user ID'))->setDescription(t('The user ID of the author of the current revision.'))->setSetting('target_type', 'user')->setQueryable(FALSE)->setRevisionable(TRUE);
     $fields['revision_log'] = FieldDefinition::create('string_long')->setLabel(t('Revision log message'))->setDescription(t('The log entry explaining the changes in this revision.'))->setRevisionable(TRUE)->setTranslatable(TRUE);
     return $fields;
 }
예제 #23
0
파일: Feed.php 프로젝트: alnutile/drunatra
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['fid'] = FieldDefinition::create('integer')->setLabel(t('Feed ID'))->setDescription(t('The ID of the aggregator feed.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['uuid'] = FieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The aggregator feed UUID.'))->setReadOnly(TRUE);
     $fields['title'] = FieldDefinition::create('string')->setLabel(t('Title'))->setDescription(t('The name of the feed (or the name of the website providing the feed).'))->setRequired(TRUE)->setSetting('max_length', 255)->setDisplayOptions('form', array('type' => 'string', 'weight' => -5));
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The feed language code.'));
     $fields['url'] = FieldDefinition::create('uri')->setLabel(t('URL'))->setDescription(t('The fully-qualified URL of the feed.'))->setRequired(TRUE)->setDisplayOptions('form', array('type' => 'uri', 'weight' => -3));
     $intervals = array(900, 1800, 3600, 7200, 10800, 21600, 32400, 43200, 64800, 86400, 172800, 259200, 604800, 1209600, 2419200);
     $period = array_map('format_interval', array_combine($intervals, $intervals));
     $period[AGGREGATOR_CLEAR_NEVER] = t('Never');
     $fields['refresh'] = FieldDefinition::create('list_integer')->setLabel(t('Update interval'))->setDescription(t('The length of time between feed updates. Requires a correctly configured <a href="@cron">cron maintenance task</a>.', array('@cron' => url('admin/reports/status'))))->setSetting('unsigned', TRUE)->setRequired(TRUE)->setSetting('allowed_values', $period)->setDisplayOptions('form', array('type' => 'options_select', 'weight' => -2));
     $fields['checked'] = FieldDefinition::create('timestamp')->setLabel(t('Checked'))->setDescription(t('Last time feed was checked for new items, as Unix timestamp.'))->setDefaultValue(0);
     $fields['queued'] = FieldDefinition::create('timestamp')->setLabel(t('Queued'))->setDescription(t('Time when this feed was queued for refresh, 0 if not queued.'))->setDefaultValue(0);
     $fields['link'] = FieldDefinition::create('uri')->setLabel(t('Link'))->setDescription(t('The link of the feed.'));
     $fields['description'] = FieldDefinition::create('string_long')->setLabel(t('Description'))->setDescription(t("The parent website's description that comes from the !description element in the feed.", array('!description' => '<description>')));
     $fields['image'] = FieldDefinition::create('uri')->setLabel(t('Image'))->setDescription(t('An image representing the feed.'));
     $fields['hash'] = FieldDefinition::create('string')->setLabel(t('Hash'))->setDescription(t('Calculated hash of the feed data, used for validating cache.'));
     $fields['etag'] = FieldDefinition::create('string')->setLabel(t('Etag'))->setDescription(t('Entity tag HTTP response header, used for validating cache.'));
     // This is updated by the fetcher and not when the feed is saved, therefore
     // it's a timestamp and not a changed field.
     $fields['modified'] = FieldDefinition::create('timestamp')->setLabel(t('Modified'))->setDescription(t('When the feed was last modified, as a Unix timestamp.'));
     return $fields;
 }
예제 #24
0
 /**
  * {@inheritdoc}
  */
 public static function createFromItemType($item_type)
 {
     // Forward to the field definition class for creating new data definitions
     // via the typed manager.
     return FieldDefinition::createFromItemType($item_type);
 }
예제 #25
0
/**
 * Provides field definitions for a specific bundle within an entity type.
 *
 * Bundle fields either have to override an existing base field, or need to
 * provide a field storage definition via hook_entity_field_storage_info()
 * unless they are computed.
 *
 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
 *   The entity type definition.
 * @param string $bundle
 *   The bundle.
 * @param \Drupal\Core\Field\FieldDefinitionInterface[] $base_field_definitions
 *   The list of base field definitions for the entity type.
 *
 * @return \Drupal\Core\Field\FieldDefinitionInterface[]
 *   An array of bundle field definitions, keyed by field name.
 *
 * @see hook_entity_base_field_info()
 * @see hook_entity_base_field_info_alter()
 * @see hook_entity_field_storage_info()
 * @see hook_entity_field_storage_info_alter()
 * @see hook_entity_bundle_field_info_alter()
 * @see \Drupal\Core\Field\FieldDefinitionInterface
 * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldDefinitions()
 */
function hook_entity_bundle_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle, array $base_field_definitions)
{
    // Add a property only to nodes of the 'article' bundle.
    if ($entity_type->id() == 'node' && $bundle == 'article') {
        $fields = array();
        $fields['mymodule_text_more'] = FieldDefinition::create('string')->setLabel(t('More text'))->setComputed(TRUE)->setClass('\\Drupal\\mymodule\\EntityComputedMoreText');
        return $fields;
    }
}
예제 #26
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['category'] = FieldDefinition::create('entity_reference')->setLabel(t('Category ID'))->setDescription(t('The ID of the associated category.'))->setSetting('target_type', 'contact_category')->setRequired(TRUE);
     $fields['uuid'] = FieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The message UUID.'))->setReadOnly(TRUE);
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The comment language code.'));
     $fields['name'] = FieldDefinition::create('string')->setLabel(t("The sender's name"))->setDescription(t('The name of the person that is sending the contact message.'));
     $fields['mail'] = FieldDefinition::create('email')->setLabel(t("The sender's email"))->setDescription(t('The email of the person that is sending the contact message.'));
     // The subject of the contact message.
     $fields['subject'] = FieldDefinition::create('string')->setLabel(t('Subject'))->setRequired(TRUE)->setSetting('max_length', 100)->setDisplayOptions('form', array('type' => 'string', 'weight' => -10))->setDisplayConfigurable('form', TRUE);
     // The text of the contact message.
     $fields['message'] = FieldDefinition::create('string_long')->setLabel(t('Message'))->setRequired(TRUE)->setDisplayOptions('form', array('type' => 'string_textarea', 'weight' => 0, 'settings' => array('rows' => 12)))->setDisplayConfigurable('form', TRUE)->setDisplayOptions('view', array('type' => 'string', 'weight' => 0, 'label' => 'above'))->setDisplayConfigurable('view', TRUE);
     $fields['copy'] = FieldDefinition::create('boolean')->setLabel(t('Copy'))->setDescription(t('Whether to send a copy of the message to the sender.'));
     $fields['recipient'] = FieldDefinition::create('entity_reference')->setLabel(t('Recipient ID'))->setDescription(t('The ID of the recipient user for personal contact messages.'))->setSetting('target_type', 'user');
     return $fields;
 }
예제 #27
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['cid'] = FieldDefinition::create('integer')->setLabel(t('Comment ID'))->setDescription(t('The comment ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['uuid'] = FieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The comment UUID.'))->setReadOnly(TRUE);
     $fields['pid'] = FieldDefinition::create('entity_reference')->setLabel(t('Parent ID'))->setDescription(t('The parent comment ID if this is a reply to a comment.'))->setSetting('target_type', 'comment');
     $fields['entity_id'] = FieldDefinition::create('entity_reference')->setLabel(t('Entity ID'))->setDescription(t('The ID of the entity of which this comment is a reply.'))->setRequired(TRUE);
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The comment language code.'));
     $fields['subject'] = FieldDefinition::create('string')->setLabel(t('Subject'))->setTranslatable(TRUE)->setSetting('max_length', 64)->setDisplayOptions('form', array('type' => 'string', 'weight' => 10))->setDisplayConfigurable('form', TRUE);
     $fields['uid'] = FieldDefinition::create('entity_reference')->setLabel(t('User ID'))->setDescription(t('The user ID of the comment author.'))->setTranslatable(TRUE)->setSetting('target_type', 'user')->setDefaultValue(0);
     $fields['name'] = FieldDefinition::create('string')->setLabel(t('Name'))->setDescription(t("The comment author's name."))->setTranslatable(TRUE)->setSetting('max_length', 60)->setDefaultValue('')->addConstraint('CommentName', array());
     $fields['mail'] = FieldDefinition::create('email')->setLabel(t('Email'))->setDescription(t("The comment author's email address."))->setTranslatable(TRUE);
     $fields['homepage'] = FieldDefinition::create('uri')->setLabel(t('Homepage'))->setDescription(t("The comment author's home page address."))->setTranslatable(TRUE)->setSetting('max_length', 255);
     $fields['hostname'] = FieldDefinition::create('string')->setLabel(t('Hostname'))->setDescription(t("The comment author's hostname."))->setTranslatable(TRUE)->setSetting('max_length', 128);
     $fields['created'] = FieldDefinition::create('created')->setLabel(t('Created'))->setDescription(t('The time that the comment was created.'))->setTranslatable(TRUE);
     $fields['changed'] = FieldDefinition::create('changed')->setLabel(t('Changed'))->setDescription(t('The time that the comment was last edited.'))->setTranslatable(TRUE);
     $fields['status'] = FieldDefinition::create('boolean')->setLabel(t('Publishing status'))->setDescription(t('A boolean indicating whether the comment is published.'))->setTranslatable(TRUE)->setDefaultValue(TRUE);
     $fields['thread'] = FieldDefinition::create('string')->setLabel(t('Thread place'))->setDescription(t("The alphadecimal representation of the comment's place in a thread, consisting of a base 36 string prefixed by an integer indicating its length."))->setSetting('max_length', 255);
     $fields['entity_type'] = FieldDefinition::create('string')->setLabel(t('Entity type'))->setDescription(t('The entity type to which this comment is attached.'))->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH);
     $fields['comment_type'] = FieldDefinition::create('entity_reference')->setLabel(t('Comment Type'))->setDescription(t('The comment type.'))->setSetting('target_type', 'comment_type');
     $fields['field_name'] = FieldDefinition::create('string')->setLabel(t('Comment field name'))->setDescription(t('The field name through which this comment was added.'))->setSetting('max_length', FieldStorageConfig::NAME_MAX_LENGTH);
     return $fields;
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->id = 1;
     $values = array('id' => $this->id, 'langcode' => 'en', 'uuid' => '3bb9ee60-bea5-4622-b89b-a63319d10b3a');
     $this->entityTypeId = $this->randomName();
     $this->bundle = $this->randomName();
     $this->entityType = $this->getMock('\\Drupal\\Core\\Entity\\EntityTypeInterface');
     $this->entityType->expects($this->any())->method('getKeys')->will($this->returnValue(array('id' => 'id', 'uuid' => 'uuid')));
     $this->entityManager = $this->getMock('\\Drupal\\Core\\Entity\\EntityManagerInterface');
     $this->entityManager->expects($this->any())->method('getDefinition')->with($this->entityTypeId)->will($this->returnValue($this->entityType));
     $this->uuid = $this->getMock('\\Drupal\\Component\\Uuid\\UuidInterface');
     $this->typedDataManager = $this->getMockBuilder('\\Drupal\\Core\\TypedData\\TypedDataManager')->disableOriginalConstructor()->getMock();
     $language = new Language(array('id' => 'en'));
     $this->languageManager = $this->getMock('\\Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->languageManager->expects($this->any())->method('getLanguages')->will($this->returnValue(array('en' => $language)));
     $this->languageManager->expects($this->any())->method('getLanguage')->with('en')->will($this->returnValue($language));
     $this->fieldTypePluginManager = $this->getMockBuilder('\\Drupal\\Core\\Field\\FieldTypePluginManager')->disableOriginalConstructor()->getMock();
     $this->fieldTypePluginManager->expects($this->any())->method('getDefaultSettings')->will($this->returnValue(array()));
     $this->fieldTypePluginManager->expects($this->any())->method('getDefaultInstanceSettings')->will($this->returnValue(array()));
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
     $container->set('uuid', $this->uuid);
     $container->set('typed_data_manager', $this->typedDataManager);
     $container->set('language_manager', $this->languageManager);
     $container->set('plugin.manager.field.field_type', $this->fieldTypePluginManager);
     \Drupal::setContainer($container);
     $this->fieldDefinitions = array('id' => FieldDefinition::create('integer'), 'revision_id' => FieldDefinition::create('integer'));
     $this->entityManager->expects($this->any())->method('getFieldDefinitions')->with($this->entityTypeId, $this->bundle)->will($this->returnValue($this->fieldDefinitions));
     $this->entity = $this->getMockForAbstractClass('\\Drupal\\Core\\Entity\\ContentEntityBase', array($values, $this->entityTypeId, $this->bundle));
 }
예제 #29
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['id'] = FieldDefinition::create('integer')->setLabel(t('Entity ID'))->setDescription(t('The entity ID for this menu link content entity.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['uuid'] = FieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The content menu link UUID.'))->setReadOnly(TRUE);
     $fields['bundle'] = FieldDefinition::create('string')->setLabel(t('Bundle'))->setDescription(t('The content menu link bundle.'))->setSetting('max_length', EntityTypeInterface::BUNDLE_MAX_LENGTH)->setReadOnly(TRUE);
     $fields['title'] = FieldDefinition::create('string')->setLabel(t('Menu link title'))->setDescription(t('The text to be used for this link in the menu.'))->setRequired(TRUE)->setTranslatable(TRUE)->setSettings(array('default_value' => '', 'max_length' => 255))->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'string', 'weight' => -5))->setDisplayOptions('form', array('type' => 'string', 'weight' => -5))->setDisplayConfigurable('form', TRUE);
     $fields['description'] = FieldDefinition::create('string')->setLabel(t('Description'))->setDescription(t('Shown when hovering over the menu link.'))->setTranslatable(TRUE)->setSettings(array('default_value' => '', 'max_length' => 255))->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'string', 'weight' => 0))->setDisplayOptions('form', array('type' => 'string', 'weight' => 0));
     $fields['menu_name'] = FieldDefinition::create('string')->setLabel(t('Menu name'))->setDescription(t('The menu name. All links with the same menu name (such as "tools") are part of the same menu.'))->setSetting('default_value', 'tools');
     // @todo Use a link field https://www.drupal.org/node/2302205.
     $fields['route_name'] = FieldDefinition::create('string')->setLabel(t('Route name'))->setDescription(t('The machine name of a defined Symfony Route this menu item represents.'));
     $fields['route_parameters'] = FieldDefinition::create('map')->setLabel(t('Route parameters'))->setDescription(t('A serialized array of route parameters of this menu link.'));
     $fields['url'] = FieldDefinition::create('uri')->setLabel(t('External link url'))->setDescription(t('The url of the link, in case you have an external link.'));
     $fields['options'] = FieldDefinition::create('map')->setLabel(t('Options'))->setDescription(t('A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.'))->setSetting('default_value', array());
     $fields['external'] = FieldDefinition::create('boolean')->setLabel(t('External'))->setDescription(t('A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal).'))->setSetting('default_value', FALSE);
     $fields['weight'] = FieldDefinition::create('integer')->setLabel(t('Weight'))->setDescription(t('Link weight among links in the same menu at the same depth. In the menu, the links with high weight will sink and links with a low weight will be positioned nearer the top.'))->setSetting('default_value', 0)->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'integer', 'weight' => 0))->setDisplayOptions('form', array('type' => 'integer', 'weight' => 20));
     $fields['expanded'] = FieldDefinition::create('boolean')->setLabel(t('Show as expanded'))->setDescription(t('If selected and this menu link has children, the menu will always appear expanded.'))->setSetting('default_value', FALSE)->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'boolean', 'weight' => 0))->setDisplayOptions('form', array('settings' => array('display_label' => TRUE), 'weight' => 0));
     // @todo We manually create a form element for this, since the form logic is
     // is inverted to show enabled. Flip this to a status field and use the
     // normal entity Boolean widget. https://www.drupal.org/node/2305707
     $fields['hidden'] = FieldDefinition::create('boolean')->setLabel(t('Hidden'))->setDescription(t('A flag for whether the link should be hidden in menus or rendered normally.'))->setSetting('default_value', FALSE);
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The node language code.'));
     $fields['parent'] = FieldDefinition::create('string')->setLabel(t('Parent plugin ID'))->setDescription(t('The ID of the parent menu link plugin, or empty string when at the top level of the hierarchy.'));
     return $fields;
 }
예제 #30
0
 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['uid'] = FieldDefinition::create('integer')->setLabel(t('User ID'))->setDescription(t('The user ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['uuid'] = FieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The user UUID.'))->setReadOnly(TRUE);
     $fields['langcode'] = FieldDefinition::create('language')->setLabel(t('Language code'))->setDescription(t('The user language code.'));
     $fields['preferred_langcode'] = FieldDefinition::create('language')->setLabel(t('Preferred admin language code'))->setDescription(t("The user's preferred language code for receiving emails and viewing the site."));
     $fields['preferred_admin_langcode'] = FieldDefinition::create('language')->setLabel(t('Preferred language code'))->setDescription(t("The user's preferred language code for viewing administration pages."));
     // The name should not vary per language. The username is the visual
     // identifier for a user and needs to be consistent in all languages.
     $fields['name'] = FieldDefinition::create('string')->setLabel(t('Name'))->setDescription(t('The name of this user.'))->setDefaultValue('')->setPropertyConstraints('value', array('UserName' => array(), 'UserNameUnique' => array()));
     $fields['pass'] = FieldDefinition::create('string')->setLabel(t('Password'))->setDescription(t('The password of this user (hashed).'));
     $fields['mail'] = FieldDefinition::create('email')->setLabel(t('Email'))->setDescription(t('The email of this user.'))->setDefaultValue('')->setPropertyConstraints('value', array('UserMailUnique' => array()));
     // @todo Convert to a text field in https://drupal.org/node/1548204.
     $fields['signature'] = FieldDefinition::create('string')->setLabel(t('Signature'))->setDescription(t('The signature of this user.'));
     $fields['signature_format'] = FieldDefinition::create('string')->setLabel(t('Signature format'))->setDescription(t('The signature format of this user.'));
     $fields['timezone'] = FieldDefinition::create('string')->setLabel(t('Timezone'))->setDescription(t('The timezone of this user.'))->setSetting('max_length', 32);
     $fields['status'] = FieldDefinition::create('boolean')->setLabel(t('User status'))->setDescription(t('Whether the user is active or blocked.'))->setDefaultValue(FALSE);
     $fields['created'] = FieldDefinition::create('created')->setLabel(t('Created'))->setDescription(t('The time that the user was created.'));
     $fields['access'] = FieldDefinition::create('timestamp')->setLabel(t('Last access'))->setDescription(t('The time that the user last accessed the site.'))->setDefaultValue(0);
     $fields['login'] = FieldDefinition::create('timestamp')->setLabel(t('Last login'))->setDescription(t('The time that the user last logged in.'))->setDefaultValue(0);
     $fields['init'] = FieldDefinition::create('email')->setLabel(t('Initial email'))->setDescription(t('The email address used for initial account creation.'))->setDefaultValue('');
     // @todo Convert this to entity_reference_field, see
     // https://drupal.org/node/2044859.
     $fields['roles'] = FieldDefinition::create('string')->setCustomStorage(TRUE)->setLabel(t('Roles'))->setCardinality(FieldDefinition::CARDINALITY_UNLIMITED)->setDescription(t('The roles the user has.'));
     return $fields;
 }