作者:davidsoloma
项目:drupalconsole.co
/**
* Creates a base field override object.
*
* @param \Drupal\Core\Field\BaseFieldDefinition $base_field_definition
* The base field definition to override.
* @param string $bundle
* The bundle to which the override applies.
*
* @return \Drupal\Core\Field\Entity\BaseFieldOverride
* A new base field override object.
*/
public static function createFromBaseFieldDefinition(BaseFieldDefinition $base_field_definition, $bundle)
{
$values = $base_field_definition->toArray();
$values['bundle'] = $bundle;
$values['baseFieldDefinition'] = $base_field_definition;
return \Drupal::entityManager()->getStorage('base_field_override')->create($values);
}
作者:ddrozdi
项目:dmap
/**
* 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));
}
作者:aWEBoLab
项目:tax
/**
* 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);
}
作者:soj
项目:d8_friendsofsilenc
/**
* 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;
}
作者:deovratj199
项目:shyamsada
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;
}
作者:penyaskit
项目:customslide
/**
* {@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;
}
作者:eigento
项目:tommiblo
/**
* Gets the field definition.
*
* A View works on an entity type across bundles, and thus only has access to
* field storage definitions. In order to be able to use widgets and
* formatters, we create a generic field definition out of that storage
* definition.
*
* @see BaseFieldDefinition::createFromFieldStorageDefinition()
*
* @return \Drupal\Core\Field\FieldDefinitionInterface
* The field definition used by this handler.
*/
protected function getFieldDefinition()
{
if (!$this->fieldDefinition) {
$field_storage_config = $this->getFieldStorageDefinition();
$this->fieldDefinition = BaseFieldDefinition::createFromFieldStorageDefinition($field_storage_config);
}
return $this->fieldDefinition;
}
作者:Hak
项目:drupal8_trainin
/**
* {@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;
}
作者:darrylr
项目:protovbmwm
/**
* {@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;
}
作者:eric-shel
项目:eric-shell-d
/**
* {@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;
}
作者:aWEBoLab
项目:tax
/**
* {@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;
}
作者:aWEBoLab
项目:tax
/**
* {@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();
}
作者:soj
项目:d8_friendsofsilenc
/**
* {@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;
}
作者:nishantkumar15
项目:drupal8.crackl
/**
* {@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();
}
作者:Nikola-xii
项目:d8intrane
/**
* {@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;
}
作者:bonrit
项目:moodl
/**
* @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;
}
作者:aWEBoLab
项目:tax
/**
* {@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 = BaseFieldDefinition::create($parts[1]);
return $field_definition->getItemDefinition();
}
作者:BlackyWhoEls
项目:myeSportsCM
public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
{
// Standard field, used as unique if primary index.
$fields['id'] = BaseFieldDefinition::create('integer')->setLabel(t('ID'))->setDescription(t('The ID of the Advertiser entity.'))->setReadOnly(TRUE);
// Standard field, unique outside of the scope of the current project.
$fields['uuid'] = BaseFieldDefinition::create('uuid')->setLabel(t('UUID'))->setDescription(t('The UUID of the Advertiser entity.'))->setReadOnly(TRUE);
// Standard field, used as unique if primary index.
$fields['name'] = BaseFieldDefinition::create('string')->setLabel(t('Name'))->setDescription(t('Name or Callsign of the Squad.'))->setReadOnly(TRUE);
return $fields;
}
作者:sedurz
项目:ildeposito
/**
* {@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;
}
作者:pedrocone
项目:hydrotool
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
{
$fields['cart_item_id'] = BaseFieldDefinition::create('integer')->setLabel(t('Cart item ID'))->setDescription(t('The cart item ID.'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE);
$fields['cart_id'] = BaseFieldDefinition::create('string')->setLabel(t('Cart ID'))->setDescription(t('A user-specific cart ID. For authenticated users, their {users}.uid. For anonymous users, a token.'))->setSetting('default_value', 0);
$fields['nid'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('Node ID'))->setDescription(t('The node ID of the product.'))->setSetting('target_type', 'node')->setSetting('default_value', 0);
$fields['qty'] = BaseFieldDefinition::create('integer')->setLabel(t('Quantity'))->setDescription(t('The number of this product in the cart.'))->setSetting('default_value', 0)->setSetting('unsigned', TRUE);
$fields['changed'] = BaseFieldDefinition::create('integer')->setLabel(t('Changed'))->setDescription(t('The Unix timestamp indicating the time the product in the cart was changed.'))->setSetting('default_value', 0);
$fields['data'] = BaseFieldDefinition::create('map')->setLabel(t('Data'))->setDescription(t('A serialized array of extra data.'));
return $fields;
}