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


PHP BaseFieldDefinition::create方法代码示例

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


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

示例1: baseFieldDefinitions

 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['gid'] = BaseFieldDefinition::create('integer')->setLabel(t('Gallery ID'))->setDescription(t('The gallery ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['title'] = BaseFieldDefinition::create('string')->setLabel(t('Title'))->setRequired(TRUE)->setSetting('max_length', 255)->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'string', 'weight' => -5))->setDisplayOptions('form', array('type' => 'string_textfield', 'weight' => -5))->setDisplayConfigurable('form', TRUE);
     $fields['description'] = BaseFieldDefinition::create('text')->setLabel(t('Description'))->setRequired(TRUE)->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'text', 'weight' => 2))->setDisplayOptions('form', array('type' => 'text_textfield', 'weight' => 2))->setDisplayConfigurable('form', TRUE);
     return $fields;
 }
开发者ID:deovratj1990,项目名称:shyamsadan,代码行数:7,代码来源:Gallery.php

示例2: revisionLogBaseFieldDefinitions

 /**
  * Provides revision-related base field definitions for an entity type.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   The entity type definition.
  *
  * @return \Drupal\Core\Field\FieldDefinitionInterface[]
  *   An array of base field definitions for the entity type, keyed by field
  *   name.
  *
  * @see \Drupal\Core\Entity\FieldableEntityInterface::baseFieldDefinitions()
  */
 public static function revisionLogBaseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['revision_created'] = BaseFieldDefinition::create('created')->setLabel(t('Revision create time'))->setDescription(t('The time that the current revision was created.'))->setRevisionable(TRUE);
     $fields['revision_user'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('Revision user'))->setDescription(t('The user ID of the author of the current revision.'))->setSetting('target_type', 'user')->setRevisionable(TRUE);
     $fields['revision_log_message'] = BaseFieldDefinition::create('string_long')->setLabel(t('Revision log message'))->setDescription(t('Briefly describe the changes you have made.'))->setRevisionable(TRUE)->setDefaultValue('')->setDisplayOptions('form', ['type' => 'string_textarea', 'weight' => 25, 'settings' => ['rows' => 4]]);
     return $fields;
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:19,代码来源:RevisionLogEntityTrait.php

示例3: testFields

 /**
  * Tests deriving metadata about fields.
  */
 public function testFields()
 {
     $field_definition = BaseFieldDefinition::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));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:35,代码来源:EntityTypedDataDefinitionTest.php

示例4: testTestItem

 /**
  * Tests using entity fields of the field field type.
  */
 public function testTestItem()
 {
     // Verify entity creation.
     $entity = EntityTest::create();
     $value = rand(1, 10);
     $entity->field_test = $value;
     $entity->name->value = $this->randomMachineName();
     $entity->save();
     // Verify entity has been created properly.
     $id = $entity->id();
     $entity = entity_load('entity_test', $id);
     $this->assertTrue($entity->{$this->fieldName} instanceof FieldItemListInterface, 'Field implements interface.');
     $this->assertTrue($entity->{$this->fieldName}[0] instanceof FieldItemInterface, 'Field item implements interface.');
     $this->assertEqual($entity->{$this->fieldName}->value, $value);
     $this->assertEqual($entity->{$this->fieldName}[0]->value, $value);
     // Verify changing the field value.
     $new_value = rand(1, 10);
     $entity->field_test->value = $new_value;
     $this->assertEqual($entity->{$this->fieldName}->value, $new_value);
     // Read changed entity and assert changed values.
     $entity->save();
     $entity = entity_load('entity_test', $id);
     $this->assertEqual($entity->{$this->fieldName}->value, $new_value);
     // Test the schema for this field type.
     $expected_schema = array('columns' => array('value' => array('type' => 'int', 'size' => 'medium')), 'unique keys' => array(), 'indexes' => array('value' => array('value')), 'foreign keys' => array());
     $field_schema = BaseFieldDefinition::create('test_field')->getSchema();
     $this->assertEqual($field_schema, $expected_schema);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:31,代码来源:TestItemTest.php

示例5: baseFieldDefinitions

 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = parent::baseFieldDefinitions($entity_type);
     $fields['name'] = BaseFieldDefinition::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))->setDisplayOptions('form', array('type' => 'string_textfield', 'weight' => -5));
     $fields['created'] = BaseFieldDefinition::create('created')->setLabel(t('Authored on'))->setDescription(t('Time the entity was created'))->setTranslatable(TRUE);
     $fields['user_id'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('User ID'))->setDescription(t('The ID of the associated user.'))->setSetting('target_type', 'user')->setSetting('handler', 'default')->setDefaultValue(array(0 => array('target_id' => 1)))->setTranslatable(TRUE)->setDisplayOptions('form', array('type' => 'entity_reference_autocomplete', 'weight' => -1, 'settings' => array('match_operator' => 'CONTAINS', 'size' => '60', 'placeholder' => '')));
     return $fields;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:11,代码来源:EntityTest.php

示例6: baseFieldDefinitions

 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['id'] = BaseFieldDefinition::create('integer')->setLabel(t('Slider ID'))->setDescription(t('The slider ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['name'] = BaseFieldDefinition::create('string')->setLabel(t('Name'))->setTranslatable(TRUE)->setDisplayOptions('view', array('label' => 'above', 'type' => 'string', 'weight' => -5))->setDisplayOptions('form', array('type' => 'string_textfield', 'weight' => -5))->setDisplayConfigurable('view', TRUE)->setDisplayConfigurable('form', TRUE);
     $fields['description'] = BaseFieldDefinition::create('string')->setLabel(t('Slider description'))->setTranslatable(TRUE)->setDescription(t('A brief description of your slider.'))->setDisplayOptions('view', array('label' => 'above', 'type' => 'string', 'weight' => -2))->setDisplayOptions('form', array('type' => 'string_textfield', 'weight' => -2))->setDisplayConfigurable('view', TRUE)->setDisplayConfigurable('form', TRUE);
     $fields['langcode'] = BaseFieldDefinition::create('language')->setLabel(t('Language'))->setDescription(t('The node language code.'))->setTranslatable(TRUE)->setDisplayOptions('view', array('type' => 'hidden'))->setDisplayOptions('form', array('type' => 'language_select', 'weight' => 2));
     return $fields;
 }
开发者ID:penyaskito,项目名称:customslider,代码行数:11,代码来源:CustomSlider.php

示例7: baseFieldDefinitions

 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = parent::baseFieldDefinitions($entity_type);
     $fields['test_no_display'] = BaseFieldDefinition::create('text')->setLabel(t('Field with no display'));
     $fields['test_display_configurable'] = BaseFieldDefinition::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'] = BaseFieldDefinition::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;
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:11,代码来源:EntityTestBaseFieldDisplay.php

示例8: baseFieldDefinitions

 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = parent::baseFieldDefinitions($entity_type);
     $fields['parent_id'] = BaseFieldDefinition::create('string')->setLabel(t('Parent ID'))->setDescription(t('The ID of the parent entity of which this entity is referenced.'));
     $fields['parent_type'] = BaseFieldDefinition::create('string')->setLabel(t('Parent type'))->setDescription(t('The entity parent type to which this entity is referenced.'));
     $fields['parent_field_name'] = BaseFieldDefinition::create('string')->setLabel(t('Parent field name'))->setDescription(t('The entity parent field name to which this entity is referenced.'));
     return $fields;
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:11,代码来源:EntityTestCompositeRelationship.php

示例9: baseFieldDefinitions

 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = [];
     $fields += static::entityKeysBaseFieldDefinitions($entity_type);
     $fields += static::entityRevisionLogBaseFieldDefinitions();
     $fields['name'] = BaseFieldDefinition::create('string')->setLabel('Name')->setRevisionable(TRUE)->setDisplayOptions('view', ['label' => 'hidden', 'type' => 'string', 'weight' => -5]);
     return $fields;
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:11,代码来源:EnhancedEntity.php

示例10: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $field_definition = BaseFieldDefinition::create('plugin:plugin_test_helper_mock');
     /** @var \Drupal\Core\Field\FieldItemListInterface $field_item_list */
     $field_item_list = \Drupal::typedDataManager()->create($field_definition);
     $field_item_list->appendItem();
     $this->fieldItem = $field_item_list->first();
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:12,代码来源:PluginCollectionItemBaseTest.php

示例11: baseFieldDefinitions

 /**
  * @inheritDoc
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['id'] = BaseFieldDefinition::create('integer')->setLabel(t('Course ID'))->setDescription(t('The course ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['fullname'] = BaseFieldDefinition::create('string')->setLabel(t('Full name'))->setRequired(TRUE)->setTranslatable(FALSE)->setRevisionable(FALSE)->setDefaultValue('')->setSetting('max_length', 255)->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'string', 'weight' => -5))->setDisplayOptions('form', array('type' => 'string_textfield', 'weight' => -5))->setDisplayConfigurable('form', TRUE);
     $fields['shortname'] = BaseFieldDefinition::create('string')->setLabel(t('Short name'))->setRequired(TRUE)->setTranslatable(FALSE)->setRevisionable(FALSE)->setDefaultValue('')->setSetting('max_length', 255);
     $fields['timemodified'] = BaseFieldDefinition::create('changed')->setLabel(t('Changed'))->setDescription(t('The time that the course was last edited.'))->setRevisionable(FALSE)->setTranslatable(FALSE);
     $fields['category'] = BaseFieldDefinition::create('integer')->setLabel(t('Category'))->setDescription(t('The category ID in which the course belongs.'))->setRevisionable(FALSE)->setTranslatable(FALSE);
     return $fields;
 }
开发者ID:bonrita,项目名称:moodle,代码行数:12,代码来源:Course.php

示例12: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Setup some fields for entity_test_extra to create.
     $definitions['multivalued_base_field'] = BaseFieldDefinition::create('string')->setName('multivalued_base_field')->setTargetEntityTypeId('entity_test_mulrev')->setTargetBundle('entity_test_mulrev')->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
     $this->state->set('entity_test_mulrev.additional_base_field_definitions', $definitions);
     $this->entityManager->clearCachedDefinitions();
     $this->tableMapping = $this->entityManager->getStorage('entity_test_mulrev')->getTableMapping();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:12,代码来源:DefaultTableMappingIntegrationTest.php

示例13: baseFieldDefinitions

 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = parent::baseFieldDefinitions($entity_type);
     $fields['test_no_display'] = BaseFieldDefinition::create('text')->setLabel(t('Field with no display'));
     $fields['test_display_configurable'] = BaseFieldDefinition::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'] = BaseFieldDefinition::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));
     $fields['test_display_multiple'] = BaseFieldDefinition::create('text')->setLabel(t('A field with multiple values'))->setCardinality(FieldStorageDefinition::CARDINALITY_UNLIMITED)->setDisplayOptions('view', array('type' => 'text_default', 'weight' => 12))->setDisplayOptions('form', array('type' => 'text_textfield', 'weight' => 12));
     return $fields;
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:12,代码来源:EntityTestBaseFieldDisplay.php

示例14: baseFieldDefinitions

 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = parent::baseFieldDefinitions($entity_type);
     $fields['revision_id'] = BaseFieldDefinition::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;
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:12,代码来源:EntityTestRev.php

示例15: baseFieldDefinitions

 /**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields['id'] = BaseFieldDefinition::create('integer')->setLabel(t('Workspace ID'))->setDescription(t('The workspace ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['label'] = BaseFieldDefinition::create('string')->setLabel(t('Workaspace ID'))->setDescription(t('The workspace label.'))->setSetting('max_length', 128)->setRequired(TRUE);
     $fields['machine_name'] = BaseFieldDefinition::create('string')->setLabel(t('Workaspace ID'))->setDescription(t('The workspace machine name.'))->setSetting('max_length', 128)->setRequired(TRUE)->addPropertyConstraints('value', ['Regex' => ['pattern' => '/^[\\da-z_$()+-\\/]*$/']]);
     $fields['revision_id'] = BaseFieldDefinition::create('integer')->setLabel(t('Revision ID'))->setDescription(t('The revision ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
     $fields['uuid'] = BaseFieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The workspace UUID.'))->setReadOnly(TRUE);
     $fields['created'] = BaseFieldDefinition::create('string')->setLabel(t('Created'))->setDescription(t('The UNIX timestamp of when the workspace has been created.'));
     return $fields;
 }
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:13,代码来源:Workspace.php


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