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


PHP EntityTypeInterface::set方法代码示例

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


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

示例1: testGetEntityFromRouteMatchAddEntity

 /**
  * Tests EntityForm::getEntityFromRouteMatch() with a config entity bundle.
  *
  * @covers ::getEntityFromRouteMatch
  */
 public function testGetEntityFromRouteMatchAddEntity()
 {
     $entity = $this->prophesize(EntityInterface::class)->reveal();
     $bundle_entity_type_id = 'entity_test_bundle';
     $bundle = 'test_entity_bundle';
     $this->entityType->set('bundle_entity_type', $bundle_entity_type_id);
     $storage = $this->setUpStorage();
     // Test without a bundle parameter in the route.
     $storage->create([])->willReturn($entity);
     $route_match = new RouteMatch('test_route', new Route('/entity-test/add'));
     $actual = $this->entityForm->getEntityFromRouteMatch($route_match, $this->entityType->id());
     $this->assertEquals($entity, $actual);
     // Test with an entity bundle parameter.
     $storage->create(['bundle' => $bundle])->willReturn($entity);
     $bundle_entity = $this->prophesize(EntityInterface::class);
     $bundle_entity->id()->willReturn('test_entity_bundle');
     $route_match = new RouteMatch('test_route', new Route('/entity-test/add/{entity_test_bundle}'), [$bundle_entity_type_id => $bundle_entity->reveal()], [$bundle_entity_type_id => $bundle]);
     $actual = $this->entityForm->getEntityFromRouteMatch($route_match, $this->entityType->id());
     $this->assertEquals($entity, $actual);
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:25,代码来源:EntityFormTest.php

示例2: testRevisionTableFields

 /**
  * Tests fields on the revision table.
  */
 public function testRevisionTableFields()
 {
     $entity_type = $this->baseEntityType->set('base_table', 'entity_test_mulrev')->set('revision_table', 'entity_test_mulrev_revision')->set('data_table', 'entity_test_mulrev_property_data')->set('revision_data_table', 'entity_test_mulrev_property_revision')->set('id', 'entity_test_mulrev')->set('translatable', TRUE);
     $base_field_definitions = $this->setupBaseFields(EntityTestMulRev::baseFieldDefinitions($this->baseEntityType));
     $user_base_field_definitions = ['uid' => BaseFieldDefinition::create('integer')->setLabel('ID')->setDescription('The ID of the user entity.')->setReadOnly(TRUE)->setSetting('unsigned', TRUE)];
     $this->entityManager->expects($this->any())->method('getBaseFieldDefinitions')->will($this->returnValueMap([['user', $user_base_field_definitions], ['entity_test_mulrev', $base_field_definitions]]));
     $this->viewsData->setEntityType($entity_type);
     // Setup the table mapping.
     $table_mapping = $this->getMock('Drupal\\Core\\Entity\\Sql\\TableMappingInterface');
     $table_mapping->expects($this->any())->method('getTableNames')->willReturn(['entity_test_mulrev', 'entity_test_mulrev_revision', 'entity_test_mulrev_property_data', 'entity_test_mulrev_property_revision']);
     $table_mapping->expects($this->any())->method('getColumnNames')->willReturnMap([['id', ['value' => 'id']], ['uuid', ['value' => 'uuid']], ['type', ['value' => 'type']], ['langcode', ['value' => 'langcode']], ['name', ['value' => 'name']], ['description', ['value' => 'description__value', 'format' => 'description__format']], ['homepage', ['value' => 'homepage']], ['user_id', ['target_id' => 'user_id']], ['revision_id', ['value' => 'id']]]);
     $table_mapping->expects($this->any())->method('getFieldNames')->willReturnMap([['entity_test_mulrev', ['id', 'revision_id', 'uuid', 'type']], ['entity_test_mulrev_revision', ['id', 'revision_id', 'langcode']], ['entity_test_mulrev_property_data', ['id', 'revision_id', 'langcode', 'name', 'description', 'homepage', 'user_id']], ['entity_test_mulrev_property_revision', ['id', 'revision_id', 'langcode', 'name', 'description', 'homepage', 'user_id']]]);
     $table_mapping->expects($this->any())->method('getFieldTableName')->willReturnCallback(function ($field) {
         if ($field == 'uuid') {
             return 'entity_test_mulrev';
         }
         return 'entity_test_mulrev_property_data';
     });
     $this->entityStorage->expects($this->once())->method('getTableMapping')->willReturn($table_mapping);
     $this->setupFieldStorageDefinition();
     $data = $this->viewsData->getViewsData();
     // Check the base fields.
     $this->assertFalse(isset($data['entity_test_mulrev']['id']));
     $this->assertFalse(isset($data['entity_test_mulrev']['type']));
     $this->assertFalse(isset($data['entity_test_mulrev']['revision_id']));
     $this->assertUuidField($data['entity_test_mulrev']['uuid']);
     $this->assertField($data['entity_test_mulrev']['uuid'], 'uuid');
     // Also ensure that field_data only fields don't appear on the base table.
     $this->assertFalse(isset($data['entity_test_mulrev']['name']));
     $this->assertFalse(isset($data['entity_test_mul']['description']));
     $this->assertFalse(isset($data['entity_test_mul']['description__value']));
     $this->assertFalse(isset($data['entity_test_mul']['description__format']));
     $this->assertFalse(isset($data['entity_test_mul']['homepage']));
     $this->assertFalse(isset($data['entity_test_mulrev']['langcode']));
     $this->assertFalse(isset($data['entity_test_mulrev']['user_id']));
     // Check the revision fields. The revision ID should only appear in the data
     // table.
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['revision_id']));
     // Also ensure that field_data only fields don't appear on the revision table.
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['id']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['name']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['description']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['description__value']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['description__format']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['homepage']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['user_id']));
     // Check the data fields.
     $this->assertNumericField($data['entity_test_mulrev_property_data']['id']);
     $this->assertField($data['entity_test_mulrev_property_data']['id'], 'id');
     $this->assertNumericField($data['entity_test_mulrev_property_data']['revision_id']);
     $this->assertField($data['entity_test_mulrev_property_data']['revision_id'], 'revision_id');
     $this->assertLanguageField($data['entity_test_mulrev_property_data']['langcode']);
     $this->assertField($data['entity_test_mulrev_property_data']['langcode'], 'langcode');
     $this->assertStringField($data['entity_test_mulrev_property_data']['name']);
     $this->assertField($data['entity_test_mulrev_property_data']['name'], 'name');
     $this->assertLongTextField($data['entity_test_mulrev_property_data'], 'description');
     $this->assertField($data['entity_test_mulrev_property_data']['description__value'], 'description');
     $this->assertField($data['entity_test_mulrev_property_data']['description__format'], 'description');
     $this->assertUriField($data['entity_test_mulrev_property_data']['homepage']);
     $this->assertField($data['entity_test_mulrev_property_data']['homepage'], 'homepage');
     $this->assertEntityReferenceField($data['entity_test_mulrev_property_data']['user_id']);
     $this->assertField($data['entity_test_mulrev_property_data']['user_id'], 'user_id');
     $relationship = $data['entity_test_mulrev_property_data']['user_id']['relationship'];
     $this->assertEquals('users_field_data', $relationship['base']);
     $this->assertEquals('uid', $relationship['base field']);
     // Check the property data fields.
     $this->assertNumericField($data['entity_test_mulrev_property_revision']['id']);
     $this->assertField($data['entity_test_mulrev_property_revision']['id'], 'id');
     $this->assertLanguageField($data['entity_test_mulrev_property_revision']['langcode']);
     $this->assertField($data['entity_test_mulrev_property_revision']['langcode'], 'langcode');
     $this->assertEquals('Translation language', $data['entity_test_mulrev_property_revision']['langcode']['title']);
     $this->assertStringField($data['entity_test_mulrev_property_revision']['name']);
     $this->assertField($data['entity_test_mulrev_property_revision']['name'], 'name');
     $this->assertLongTextField($data['entity_test_mulrev_property_revision'], 'description');
     $this->assertField($data['entity_test_mulrev_property_revision']['description__value'], 'description');
     $this->assertField($data['entity_test_mulrev_property_revision']['description__format'], 'description');
     $this->assertUriField($data['entity_test_mulrev_property_revision']['homepage']);
     $this->assertField($data['entity_test_mulrev_property_revision']['homepage'], 'homepage');
     $this->assertEntityReferenceField($data['entity_test_mulrev_property_revision']['user_id']);
     $this->assertField($data['entity_test_mulrev_property_revision']['user_id'], 'user_id');
     $relationship = $data['entity_test_mulrev_property_revision']['user_id']['relationship'];
     $this->assertEquals('users_field_data', $relationship['base']);
     $this->assertEquals('uid', $relationship['base field']);
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:87,代码来源:EntityViewsDataTest.php

示例3: testRevisionTableFields

 /**
  * Tests fields on the revision table.
  */
 public function testRevisionTableFields()
 {
     $entity_type = $this->baseEntityType->set('base_table', 'entity_test_mulrev')->set('revision_table', 'entity_test_mulrev_revision')->set('data_table', 'entity_test_mulrev_property_data')->set('revision_data_table', 'entity_test_mulrev_property_revision')->set('id', 'entity_test_mulrev');
     $base_field_definitions = $this->setupBaseFields(EntityTestMulRev::baseFieldDefinitions($this->baseEntityType));
     $this->entityManager->expects($this->once())->method('getBaseFieldDefinitions')->with('entity_test_mulrev')->willReturn($base_field_definitions);
     $this->viewsData->setEntityType($entity_type);
     // Setup the table mapping.
     $table_mapping = $this->getMock('Drupal\\Core\\Entity\\Sql\\TableMappingInterface');
     $table_mapping->expects($this->any())->method('getTableNames')->willReturn(['entity_test_mulrev', 'entity_test_mulrev_revision', 'entity_test_mulrev_property_data', 'entity_test_mulrev_property_revision']);
     $table_mapping->expects($this->any())->method('getColumnNames')->willReturnMap([['id', ['value' => 'id']], ['uuid', ['value' => 'uuid']], ['type', ['value' => 'type']], ['langcode', ['value' => 'langcode']], ['name', ['value' => 'name']], ['description', ['value' => 'description__value', 'format' => 'description__format']], ['homepage', ['value' => 'homepage']], ['user_id', ['target_id' => 'user_id']], ['revision_id', ['value' => 'id']]]);
     $table_mapping->expects($this->any())->method('getFieldNames')->willReturnMap([['entity_test_mulrev', ['id', 'revision_id', 'uuid', 'type']], ['entity_test_mulrev_revision', ['id', 'revision_id', 'langcode']], ['entity_test_mulrev_property_data', ['id', 'revision_id', 'langcode', 'name', 'description', 'homepage', 'user_id']], ['entity_test_mulrev_property_revision', ['id', 'revision_id', 'langcode', 'name', 'description', 'homepage', 'user_id']]]);
     $this->entityStorage->expects($this->once())->method('getTableMapping')->willReturn($table_mapping);
     $this->setupFieldStorageDefinition();
     $data = $this->viewsData->getViewsData();
     // Check the base fields.
     $this->assertNumericField($data['entity_test_mulrev']['id']);
     $this->assertNumericField($data['entity_test_mulrev']['revision_id']);
     $this->assertUuidField($data['entity_test_mulrev']['uuid']);
     $this->assertStringField($data['entity_test_mulrev']['type']);
     // Also ensure that field_data only fields don't appear on the base table.
     $this->assertFalse(isset($data['entity_test_mulrev']['name']));
     $this->assertFalse(isset($data['entity_test_mul']['description']));
     $this->assertFalse(isset($data['entity_test_mul']['description__value']));
     $this->assertFalse(isset($data['entity_test_mul']['description__format']));
     $this->assertFalse(isset($data['entity_test_mul']['homepage']));
     $this->assertFalse(isset($data['entity_test_mulrev']['langcode']));
     $this->assertFalse(isset($data['entity_test_mulrev']['user_id']));
     // Check the revision fields.
     $this->assertNumericField($data['entity_test_mulrev_revision']['id']);
     $this->assertNumericField($data['entity_test_mulrev_revision']['revision_id']);
     $this->assertLanguageField($data['entity_test_mulrev_revision']['langcode']);
     $this->assertEquals('Original language', $data['entity_test_mulrev_revision']['langcode']['title']);
     // Also ensure that field_data only fields don't appear on the revision table.
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['name']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['description']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['description__value']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['description__format']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['homepage']));
     $this->assertFalse(isset($data['entity_test_mulrev_revision']['user_id']));
     // Check the data fields.
     $this->assertNumericField($data['entity_test_mulrev_property_data']['id']);
     $this->assertLanguageField($data['entity_test_mulrev_property_data']['langcode']);
     $this->assertStringField($data['entity_test_mulrev_property_data']['name']);
     $this->assertLongTextField($data['entity_test_mulrev_property_data'], 'description');
     $this->assertUriField($data['entity_test_mulrev_property_data']['homepage']);
     $this->assertEntityReferenceField($data['entity_test_mulrev_property_data']['user_id']);
     $relationship = $data['entity_test_mulrev_property_data']['user_id']['relationship'];
     $this->assertEquals('users', $relationship['base']);
     $this->assertEquals('uid', $relationship['base field']);
     // Check the property data fields.
     $this->assertNumericField($data['entity_test_mulrev_property_revision']['id']);
     $this->assertLanguageField($data['entity_test_mulrev_property_revision']['langcode']);
     $this->assertEquals('Translation language', $data['entity_test_mulrev_property_revision']['langcode']['title']);
     $this->assertStringField($data['entity_test_mulrev_property_revision']['name']);
     $this->assertLongTextField($data['entity_test_mulrev_property_revision'], 'description');
     $this->assertUriField($data['entity_test_mulrev_property_revision']['homepage']);
     $this->assertEntityReferenceField($data['entity_test_mulrev_property_revision']['user_id']);
     $relationship = $data['entity_test_mulrev_property_revision']['user_id']['relationship'];
     $this->assertEquals('users', $relationship['base']);
     $this->assertEquals('uid', $relationship['base field']);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:64,代码来源:EntityViewsDataTest.php


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