• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP entity_test_create_bundle函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中entity_test_create_bundle函数的典型用法代码示例。如果您正苦于以下问题:PHP entity_test_create_bundle函数的具体用法?PHP entity_test_create_bundle怎么用?PHP entity_test_create_bundle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('taxonomy_term');
     // We want a taxonomy term reference field. It needs a vocabulary, terms,
     // a field storage and a field. First, create the vocabulary.
     $vocabulary = entity_create('taxonomy_vocabulary', array('vid' => Unicode::strtolower($this->randomMachineName())));
     $vocabulary->save();
     // Second, create the field.
     $this->fieldName = strtolower($this->randomMachineName());
     entity_create('field_storage_config', array('field_name' => $this->fieldName, 'entity_type' => 'entity_test', 'type' => 'taxonomy_term_reference', 'settings' => array('allowed_values' => array(array('vocabulary' => $vocabulary->id())))))->save();
     entity_test_create_bundle('test_bundle');
     // Third, create the instance.
     entity_create('field_config', array('entity_type' => 'entity_test', 'field_name' => $this->fieldName, 'bundle' => 'test_bundle'))->save();
     // Create two terms and also two accounts.
     for ($i = 0; $i <= 1; $i++) {
         $term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'vid' => $vocabulary->id()));
         $term->save();
         $this->terms[] = $term;
         $this->accounts[] = $this->createUser();
     }
     // Create three entity_test entities, the 0th entity will point to the
     // 0th account and 0th term, the 1st and 2nd entity will point to the
     // 1st account and 1st term.
     for ($i = 0; $i <= 2; $i++) {
         $entity = entity_create('entity_test', array('type' => 'test_bundle'));
         $entity->name->value = $this->randomMachineName();
         $index = $i ? 1 : 0;
         $entity->user_id->target_id = $this->accounts[$index]->id();
         $entity->{$this->fieldName}->target_id = $this->terms[$index]->id();
         $entity->save();
         $this->entities[] = $entity;
     }
     $this->factory = \Drupal::service('entity.query');
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:35,代码来源:EntityQueryRelationshipTest.php


示例2: testHookEntityDisplayBuildAlter

 /**
  * Test hook_entity_display_build_alter().
  */
 public function testHookEntityDisplayBuildAlter()
 {
     entity_test_create_bundle('display_build_alter_bundle');
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     $entity_ids = [];
     // Create some entities to test.
     for ($i = 0; $i < 5; $i++) {
         $entity = EntityTest::create(['name' => $this->randomMachineName(), 'type' => 'display_build_alter_bundle']);
         $entity->save();
         $entity_ids[] = $entity->id();
     }
     /** @var \Drupal\entity_test\EntityTestViewBuilder $view_builder */
     $view_builder = $this->container->get('entity_type.manager')->getViewBuilder('entity_test');
     /** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
     $storage = $this->container->get('entity_type.manager')->getStorage('entity_test');
     $storage->resetCache();
     $entities = $storage->loadMultiple($entity_ids);
     $build = $view_builder->viewMultiple($entities);
     $output = $renderer->renderRoot($build);
     $this->setRawContent($output->__toString());
     // Confirm that the content added in
     // entity_test_entity_display_build_alter() appears multiple times, not
     // just for the final entity.
     foreach ($entity_ids as $id) {
         $this->assertText('Content added in hook_entity_display_build_alter for entity id ' . $id);
     }
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:31,代码来源:EntityViewHookTest.php


示例3: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('taxonomy_term');
     // We want an entity reference field. It needs a vocabulary, terms, a field
     // storage and a field. First, create the vocabulary.
     $vocabulary = entity_create('taxonomy_vocabulary', array('vid' => Unicode::strtolower($this->randomMachineName())));
     $vocabulary->save();
     // Second, create the field.
     entity_test_create_bundle('test_bundle');
     $this->fieldName = strtolower($this->randomMachineName());
     $handler_settings = array('target_bundles' => array($vocabulary->id() => $vocabulary->id()), 'auto_create' => TRUE);
     $this->createEntityReferenceField('entity_test', 'test_bundle', $this->fieldName, NULL, 'taxonomy_term', 'default', $handler_settings);
     // Create two terms and also two accounts.
     for ($i = 0; $i <= 1; $i++) {
         $term = entity_create('taxonomy_term', array('name' => $this->randomMachineName(), 'vid' => $vocabulary->id()));
         $term->save();
         $this->terms[] = $term;
         $this->accounts[] = $this->createUser();
     }
     // Create three entity_test entities, the 0th entity will point to the
     // 0th account and 0th term, the 1st and 2nd entity will point to the
     // 1st account and 1st term.
     for ($i = 0; $i <= 2; $i++) {
         $entity = entity_create('entity_test', array('type' => 'test_bundle'));
         $entity->name->value = $this->randomMachineName();
         $index = $i ? 1 : 0;
         $entity->user_id->target_id = $this->accounts[$index]->id();
         $entity->{$this->fieldName}->target_id = $this->terms[$index]->id();
         $entity->save();
         $this->entities[] = $entity;
     }
     $this->factory = \Drupal::service('entity.query');
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:34,代码来源:EntityQueryRelationshipTest.php


示例4: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('entity_test_mulrev');
     $this->installConfig(array('language'));
     $figures = Unicode::strtolower($this->randomMachineName());
     $greetings = Unicode::strtolower($this->randomMachineName());
     foreach (array($figures => 'shape', $greetings => 'text') as $field_name => $field_type) {
         $field_storage = entity_create('field_storage_config', array('field_name' => $field_name, 'entity_type' => 'entity_test_mulrev', 'type' => $field_type, 'cardinality' => 2));
         $field_storage->save();
         $field_storages[] = $field_storage;
     }
     $bundles = array();
     for ($i = 0; $i < 2; $i++) {
         // For the sake of tablesort, make sure the second bundle is higher than
         // the first one. Beware: MySQL is not case sensitive.
         do {
             $bundle = $this->randomMachineName();
         } while ($bundles && strtolower($bundles[0]) >= strtolower($bundle));
         entity_test_create_bundle($bundle);
         foreach ($field_storages as $field_storage) {
             entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => $bundle))->save();
         }
         $bundles[] = $bundle;
     }
     // Each unit is a list of field name, langcode and a column-value array.
     $units[] = array($figures, 'en', array('color' => 'red', 'shape' => 'triangle'));
     $units[] = array($figures, 'en', array('color' => 'blue', 'shape' => 'circle'));
     // To make it easier to test sorting, the greetings get formats according
     // to their langcode.
     $units[] = array($greetings, 'tr', array('value' => 'merhaba', 'format' => 'format-tr'));
     $units[] = array($greetings, 'pl', array('value' => 'siema', 'format' => 'format-pl'));
     // Make these languages available to the greetings field.
     ConfigurableLanguage::createFromLangcode('tr')->save();
     ConfigurableLanguage::createFromLangcode('pl')->save();
     // Calculate the cartesian product of the unit array by looking at the
     // bits of $i and add the unit at the bits that are 1. For example,
     // decimal 13 is binary 1101 so unit 3,2 and 0 will be added to the
     // entity.
     for ($i = 1; $i <= 15; $i++) {
         $entity = EntityTestMulRev::create(array('type' => $bundles[$i & 1], 'name' => $this->randomMachineName(), 'langcode' => 'en'));
         // Make sure the name is set for every language that we might create.
         foreach (array('tr', 'pl') as $langcode) {
             $entity->addTranslation($langcode)->name = $this->randomMachineName();
         }
         foreach (array_reverse(str_split(decbin($i))) as $key => $bit) {
             if ($bit) {
                 list($field_name, $langcode, $values) = $units[$key];
                 $entity->getTranslation($langcode)->{$field_name}[] = $values;
             }
         }
         $entity->save();
     }
     $this->bundles = $bundles;
     $this->figures = $figures;
     $this->greetings = $greetings;
     $this->factory = \Drupal::service('entity.query');
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:58,代码来源:EntityQueryTest.php


示例5: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setup();
     $this->installEntitySchema('node');
     $this->installEntitySchema('taxonomy_term');
     $this->installEntitySchema('entity_test');
     $this->nodeType = NodeType::create(['type' => Unicode::strtolower($this->randomMachineName()), 'name' => $this->randomString()]);
     $this->nodeType->save();
     $this->vocabulary = Vocabulary::create(['vid' => Unicode::strtolower($this->randomMachineName()), 'name' => $this->randomString()]);
     $this->vocabulary->save();
     // Create a custom bundle.
     $this->customBundle = 'test_bundle_' . Unicode::strtolower($this->randomMachineName());
     entity_test_create_bundle($this->customBundle, NULL, 'entity_test');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:17,代码来源:EntityReferenceSettingsTest.php


示例6: createEntity

 /**
  * {@inheritdoc}
  */
 protected function createEntity()
 {
     // Create a "bar" bundle for the "entity_test" entity type and create.
     $bundle = 'bar';
     entity_test_create_bundle($bundle, NULL, 'entity_test');
     // Create a comment field on this bundle.
     \Drupal::service('comment.manager')->addDefaultField('entity_test', 'bar');
     // Create a "Camelids" test entity.
     $entity_test = entity_create('entity_test', array('name' => 'Camelids', 'type' => 'bar'));
     $entity_test->save();
     // Create a "Llama" comment.
     $comment = entity_create('comment', array('subject' => 'Llama', 'comment_body' => array('value' => 'The name "llama" was adopted by European settlers from native Peruvians.', 'format' => 'plain_text'), 'entity_id' => $entity_test->id(), 'entity_type' => 'entity_test', 'field_name' => 'comment', 'status' => \Drupal\comment\CommentInterface::PUBLISHED));
     $comment->save();
     return $comment;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:18,代码来源:CommentCacheTagsTest.php


示例7: testCustomBundleFieldUsage

 /**
  * Tests making use of a custom bundle field.
  */
 public function testCustomBundleFieldUsage()
 {
     entity_test_create_bundle('custom');
     // Check that an entity with bundle entity_test does not have the custom
     // field.
     $storage = $this->entityManager->getStorage('entity_test');
     $entity = $storage->create(['type' => 'entity_test']);
     $this->assertFalse($entity->hasField('custom_bundle_field'));
     // Check that the custom bundle has the defined custom field and check
     // saving and deleting of custom field data.
     $entity = $storage->create(['type' => 'custom']);
     $this->assertTrue($entity->hasField('custom_bundle_field'));
     // Ensure that the field exists in the field map.
     $field_map = \Drupal::entityManager()->getFieldMap();
     $this->assertEqual($field_map['entity_test']['custom_bundle_field'], ['type' => 'string', 'bundles' => ['custom' => 'custom']]);
     $entity->custom_bundle_field->value = 'swanky';
     $entity->save();
     $storage->resetCache();
     $entity = $storage->load($entity->id());
     $this->assertEqual($entity->custom_bundle_field->value, 'swanky', 'Entity was saved correctly');
     $entity->custom_bundle_field->value = 'cozy';
     $entity->save();
     $storage->resetCache();
     $entity = $storage->load($entity->id());
     $this->assertEqual($entity->custom_bundle_field->value, 'cozy', 'Entity was updated correctly.');
     $entity->delete();
     /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
     $table_mapping = $storage->getTableMapping();
     $table = $table_mapping->getDedicatedDataTableName($entity->getFieldDefinition('custom_bundle_field'));
     $result = $this->database->select($table, 'f')->fields('f')->condition('f.entity_id', $entity->id())->execute();
     $this->assertFalse($result->fetchAssoc(), 'Field data has been deleted');
     // Create another entity to test that values are marked as deleted when a
     // bundle is deleted.
     $entity = $storage->create(['type' => 'custom', 'custom_bundle_field' => 'new']);
     $entity->save();
     entity_test_delete_bundle('custom');
     $table = $table_mapping->getDedicatedDataTableName($entity->getFieldDefinition('custom_bundle_field'));
     $result = $this->database->select($table, 'f')->condition('f.entity_id', $entity->id())->condition('deleted', 1)->countQuery()->execute();
     $this->assertEqual(1, $result->fetchField(), 'Field data has been deleted');
     // Ensure that the field no longer exists in the field map.
     $field_map = \Drupal::entityManager()->getFieldMap();
     $this->assertFalse(isset($field_map['entity_test']['custom_bundle_field']));
     // @todo Test field purge and table deletion once supported. See
     //   https://www.drupal.org/node/2282119.
     // $this->assertFalse($this->database->schema()->tableExists($table), 'Custom field table was deleted');
 }
开发者ID:318io,项目名称:318-io,代码行数:49,代码来源:EntityBundleFieldTest.php


示例8: testAddPageWithoutBundleEntities

 /**
  * Tests the add page for an entity type not using bundle entities.
  */
 public function testAddPageWithoutBundleEntities()
 {
     entity_test_create_bundle('test', 'Test label', 'entity_test_mul');
     // Delete the default bundle, so that we can rely on our own.
     entity_test_delete_bundle('entity_test_mul', 'entity_test_mul');
     // One bundle exists, confirm redirection to the add-form.
     $this->drupalGet('/entity_test_mul/add');
     $this->assertUrl('/entity_test_mul/add/test');
     // Two bundles exist, confirm both are shown.
     entity_test_create_bundle('test2', 'Test2 label', 'entity_test_mul');
     $this->drupalGet('/entity_test_mul/add');
     $this->assertLink('Test label');
     $this->assertLink('Test2 label');
     $this->clickLink('Test2 label');
     $this->drupalGet('/entity_test_mul/add/test2');
     $this->drupalPostForm(NULL, ['name[0][value]' => 'test name'], t('Save'));
     $entity = EntityTestMul::load(1);
     $this->assertEqual('test name', $entity->label());
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:22,代码来源:EntityAddUITest.php


示例9: createEntity

 /**
  * {@inheritdoc}
  */
 protected function createEntity()
 {
     // Create a "bar" bundle for the "entity_test" entity type and create.
     $bundle = 'bar';
     entity_test_create_bundle($bundle, NULL, 'entity_test');
     // Create a comment field on this bundle.
     \Drupal::service('comment.manager')->addDefaultField('entity_test', 'bar', 'comment');
     // Display comments in a flat list; threaded comments are not render cached.
     $field = FieldConfig::loadByName('entity_test', 'bar', 'comment');
     $field->settings['default_mode'] = CommentManagerInterface::COMMENT_MODE_FLAT;
     $field->save();
     // Create a "Camelids" test entity.
     $entity_test = entity_create('entity_test', array('name' => 'Camelids', 'type' => 'bar'));
     $entity_test->save();
     // Create a "Llama" comment.
     $comment = entity_create('comment', array('subject' => 'Llama', 'comment_body' => array('value' => 'The name "llama" was adopted by European settlers from native Peruvians.', 'format' => 'plain_text'), 'entity_id' => $entity_test->id(), 'entity_type' => 'entity_test', 'field_name' => 'comment', 'status' => \Drupal\comment\CommentInterface::PUBLISHED));
     $comment->save();
     return $comment;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:22,代码来源:CommentCacheTagsTest.php


示例10: testImportCreateDefault

 /**
  * Tests creating fields and instances during default config import.
  */
 function testImportCreateDefault()
 {
     $field_name = 'field_test_import';
     $field_id = "entity_test.{$field_name}";
     $instance_id = "entity_test.entity_test.{$field_name}";
     $field_name_2 = 'field_test_import_2';
     $field_id_2 = "entity_test.{$field_name_2}";
     $instance_id_2a = "entity_test.entity_test.{$field_name_2}";
     $instance_id_2b = "entity_test.test_bundle.{$field_name_2}";
     // Check that the fields and instances do not exist yet.
     $this->assertFalse(entity_load('field_storage_config', $field_id));
     $this->assertFalse(entity_load('field_instance_config', $instance_id));
     $this->assertFalse(entity_load('field_storage_config', $field_id_2));
     $this->assertFalse(entity_load('field_instance_config', $instance_id_2a));
     $this->assertFalse(entity_load('field_instance_config', $instance_id_2b));
     // Create a second bundle for the 'Entity test' entity type.
     entity_test_create_bundle('test_bundle');
     // Enable field_test_config module and check that the field and instance
     // shipped in the module's default config were created.
     \Drupal::moduleHandler()->install(array('field_test_config'));
     // A field with one instance.
     $field_storage = entity_load('field_storage_config', $field_id);
     $this->assertTrue($field_storage, 'The field was created.');
     $instance = entity_load('field_instance_config', $instance_id);
     $this->assertTrue($instance, 'The field instance was deleted.');
     // A field with multiple instances.
     $field_storage_2 = entity_load('field_storage_config', $field_id_2);
     $this->assertTrue($field_storage_2, 'The second field was created.');
     $this->assertTrue($instance->bundle, 'test_bundle', 'The second field instance was created on bundle test_bundle.');
     $this->assertTrue($instance->bundle, 'test_bundle_2', 'The second field instance was created on bundle test_bundle_2.');
     // Tests field instances.
     $ids = \Drupal::entityQuery('field_instance_config')->condition('entity_type', 'entity_test')->condition('bundle', 'entity_test')->execute();
     $this->assertEqual(count($ids), 2);
     $this->assertTrue(isset($ids['entity_test.entity_test.field_test_import']));
     $this->assertTrue(isset($ids['entity_test.entity_test.field_test_import_2']));
     $ids = \Drupal::entityQuery('field_instance_config')->condition('entity_type', 'entity_test')->condition('bundle', 'test_bundle')->execute();
     $this->assertEqual(count($ids), 1);
     $this->assertTrue(isset($ids['entity_test.test_bundle.field_test_import_2']));
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:42,代码来源:FieldImportCreateTest.php


示例11: testImportCreateDefault

 /**
  * Tests creating field storages and fields during default config import.
  */
 function testImportCreateDefault()
 {
     $field_name = 'field_test_import';
     $field_storage_id = "entity_test.{$field_name}";
     $field_id = "entity_test.entity_test.{$field_name}";
     $field_name_2 = 'field_test_import_2';
     $field_storage_id_2 = "entity_test.{$field_name_2}";
     $field_id_2a = "entity_test.entity_test.{$field_name_2}";
     $field_id_2b = "entity_test.test_bundle.{$field_name_2}";
     // Check that the field storages and fields do not exist yet.
     $this->assertFalse(FieldStorageConfig::load($field_storage_id));
     $this->assertFalse(FieldConfig::load($field_id));
     $this->assertFalse(FieldStorageConfig::load($field_storage_id_2));
     $this->assertFalse(FieldConfig::load($field_id_2a));
     $this->assertFalse(FieldConfig::load($field_id_2b));
     // Create a second bundle for the 'Entity test' entity type.
     entity_test_create_bundle('test_bundle');
     // Enable field_test_config module and check that the field and storage
     // shipped in the module's default config were created.
     \Drupal::service('module_installer')->install(array('field_test_config'));
     // A field storage with one single field.
     $field_storage = FieldStorageConfig::load($field_storage_id);
     $this->assertTrue($field_storage, 'The field was created.');
     $field = FieldConfig::load($field_id);
     $this->assertTrue($field, 'The field was deleted.');
     // A field storage with two fields.
     $field_storage_2 = FieldStorageConfig::load($field_storage_id_2);
     $this->assertTrue($field_storage_2, 'The second field was created.');
     $this->assertTrue($field->getTargetBundle(), 'test_bundle', 'The second field was created on bundle test_bundle.');
     $this->assertTrue($field->getTargetBundle(), 'test_bundle_2', 'The second field was created on bundle test_bundle_2.');
     // Tests fields.
     $ids = \Drupal::entityQuery('field_config')->condition('entity_type', 'entity_test')->condition('bundle', 'entity_test')->execute();
     $this->assertEqual(count($ids), 2);
     $this->assertTrue(isset($ids['entity_test.entity_test.field_test_import']));
     $this->assertTrue(isset($ids['entity_test.entity_test.field_test_import_2']));
     $ids = \Drupal::entityQuery('field_config')->condition('entity_type', 'entity_test')->condition('bundle', 'test_bundle')->execute();
     $this->assertEqual(count($ids), 1);
     $this->assertTrue(isset($ids['entity_test.test_bundle.field_test_import_2']));
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:42,代码来源:FieldImportCreateTest.php


示例12: testEntityReferenceFieldValidation

 /**
  * Tests reference field validation.
  */
 public function testEntityReferenceFieldValidation()
 {
     // Test a valid reference.
     $referenced_entity = $this->container->get('entity_type.manager')->getStorage($this->referencedEntityType)->create(array('type' => $this->bundle));
     $referenced_entity->save();
     $entity = $this->container->get('entity_type.manager')->getStorage($this->entityType)->create(array('type' => $this->bundle));
     $entity->{$this->fieldName}->target_id = $referenced_entity->id();
     $violations = $entity->{$this->fieldName}->validate();
     $this->assertEqual($violations->count(), 0, 'Validation passes.');
     // Test an invalid reference.
     $entity->{$this->fieldName}->target_id = 9999;
     $violations = $entity->{$this->fieldName}->validate();
     $this->assertEqual($violations->count(), 1, 'Validation throws a violation.');
     $this->assertEqual($violations[0]->getMessage(), t('The referenced entity (%type: %id) does not exist.', array('%type' => $this->referencedEntityType, '%id' => 9999)));
     // Test a non-referenceable bundle.
     entity_test_create_bundle('non_referenceable', NULL, $this->referencedEntityType);
     $referenced_entity = entity_create($this->referencedEntityType, array('type' => 'non_referenceable'));
     $referenced_entity->save();
     $entity->{$this->fieldName}->target_id = $referenced_entity->id();
     $violations = $entity->{$this->fieldName}->validate();
     $this->assertEqual($violations->count(), 1, 'Validation throws a violation.');
     $this->assertEqual($violations[0]->getMessage(), t('This entity (%type: %id) cannot be referenced.', array('%type' => $this->referencedEntityType, '%id' => $referenced_entity->id())));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:26,代码来源:EntityReferenceFieldTest.php


示例13: testMissingBundleFieldRender

 /**
  * Tests that a field not available for every bundle is rendered as empty.
  */
 public function testMissingBundleFieldRender()
 {
     // Create a new bundle not having the test field attached.
     $bundle = $this->randomMachineName();
     entity_test_create_bundle($bundle);
     $entity = EntityTest::create(['type' => $bundle, 'name' => $this->randomString(), 'user_id' => $this->testUsers[0]->id()]);
     $entity->save();
     $executable = Views::getView('test_field_field_test');
     $executable->execute();
     $this->assertEqual('', $executable->getStyle()->getField(1, 'field_test'));
 }
开发者ID:scratch,项目名称:gai,代码行数:14,代码来源:FieldFieldTest.php


示例14: testBooleanFieldConfigTranslation

 /**
  * Tests the translation of a boolean field settings.
  */
 public function testBooleanFieldConfigTranslation()
 {
     // Add a test boolean field.
     $field_name = strtolower($this->randomMachineName());
     FieldStorageConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'boolean'])->save();
     $bundle = strtolower($this->randomMachineName());
     entity_test_create_bundle($bundle);
     $field = FieldConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => $bundle]);
     $on_label = 'On label (with <em>HTML</em> & things)';
     $field->setSetting('on_label', $on_label);
     $off_label = 'Off label (with <em>HTML</em> & things)';
     $field->setSetting('off_label', $off_label);
     $field->save();
     $this->drupalLogin($this->translatorUser);
     $this->drupalGet("/entity_test/structure/{$bundle}/fields/entity_test.{$bundle}.{$field_name}/translate");
     $this->clickLink('Add');
     // Checks the text of details summary element that surrounds the translation
     // options.
     $this->assertText(Html::escape(strip_tags($on_label)) . ' Boolean settings');
     // Checks that the correct on and off labels appear on the form.
     $this->assertEscaped($on_label);
     $this->assertEscaped($off_label);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:26,代码来源:ConfigTranslationUiTest.php


示例15: testFieldConfigTranslation

 /**
  * Tests the translation of field and field storage configuration.
  */
 public function testFieldConfigTranslation()
 {
     // Add a test field which has a translatable field setting and a
     // translatable field storage setting.
     $field_name = strtolower($this->randomMachineName());
     $field_storage = FieldStorageConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'test_field']);
     $translatable_storage_setting = $this->randomString();
     $field_storage->setSetting('translatable_storage_setting', $translatable_storage_setting);
     $field_storage->save();
     $bundle = strtolower($this->randomMachineName());
     entity_test_create_bundle($bundle);
     $field = FieldConfig::create(['field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => $bundle]);
     $translatable_field_setting = $this->randomString();
     $field->setSetting('translatable_field_setting', $translatable_field_setting);
     $field->save();
     $this->drupalLogin($this->translatorUser);
     $this->drupalGet("/entity_test/structure/{$bundle}/fields/entity_test.{$bundle}.{$field_name}/translate");
     $this->clickLink('Add');
     $this->assertText('Translatable field setting');
     $this->assertEscaped($translatable_field_setting);
     $this->assertText('Translatable storage setting');
     $this->assertEscaped($translatable_storage_setting);
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:26,代码来源:ConfigTranslationUiTest.php


示例16: testBundleFieldUpdateWithExistingData

 /**
  * Tests updating a bundle field when it has existing data.
  */
 public function testBundleFieldUpdateWithExistingData()
 {
     // Add the bundle field and run the update.
     $this->addBundleField();
     $this->entityDefinitionUpdateManager->applyUpdates();
     // Save an entity with the bundle field populated.
     entity_test_create_bundle('custom');
     $this->entityManager->getStorage('entity_test_update')->create(array('type' => 'test_bundle', 'new_bundle_field' => 'foo'))->save();
     // Change the field's field type and apply updates. It's expected to
     // throw an exception.
     $this->modifyBundleField();
     try {
         $this->entityDefinitionUpdateManager->applyUpdates();
         $this->fail('FieldStorageDefinitionUpdateForbiddenException thrown when trying to update a field schema that has data.');
     } catch (FieldStorageDefinitionUpdateForbiddenException $e) {
         $this->pass('FieldStorageDefinitionUpdateForbiddenException thrown when trying to update a field schema that has data.');
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:21,代码来源:EntityDefinitionUpdateTest.php


示例17: setUpExampleStructure

 /**
  * Sets up the necessary bundles on the test entity type.
  */
 protected function setUpExampleStructure() {
   entity_test_create_bundle('item');
   entity_test_create_bundle('article');
 }
开发者ID:jkyto,项目名称:agolf,代码行数:7,代码来源:ExampleContentTrait.php


示例18: testDeleteFieldCrossDeletion

 /**
  * Tests the cross deletion behavior between field storages and fields.
  */
 function testDeleteFieldCrossDeletion()
 {
     $field_definition_2 = $this->fieldDefinition;
     $field_definition_2['bundle'] .= '_another_bundle';
     entity_test_create_bundle($field_definition_2['bundle']);
     // Check that deletion of a field storage deletes its fields.
     $field_storage = $this->fieldStorage;
     FieldConfig::create($this->fieldDefinition)->save();
     FieldConfig::create($field_definition_2)->save();
     $field_storage->delete();
     $this->assertFalse(FieldConfig::loadByName('entity_test', $this->fieldDefinition['bundle'], $field_storage->getName()));
     $this->assertFalse(FieldConfig::loadByName('entity_test', $field_definition_2['bundle'], $field_storage->getName()));
     // Check that deletion of the last field deletes the storage.
     $field_storage = FieldStorageConfig::create($this->fieldStorageDefinition);
     $field_storage->save();
     $field = FieldConfig::create($this->fieldDefinition);
     $field->save();
     $field_2 = FieldConfig::create($field_definition_2);
     $field_2->save();
     $field->delete();
     $this->assertTrue(FieldStorageConfig::loadByName('entity_test', $field_storage->getName()));
     $field_2->delete();
     $this->assertFalse(FieldStorageConfig::loadByName('entity_test', $field_storage->getName()));
     // Check that deletion of all fields using a storage simultaneously deletes
     // the storage.
     $field_storage = FieldStorageConfig::create($this->fieldStorageDefinition);
     $field_storage->save();
     $field = FieldConfig::create($this->fieldDefinition);
     $field->save();
     $field_2 = FieldConfig::create($field_definition_2);
     $field_2->save();
     $this->container->get('entity.manager')->getStorage('field_config')->delete(array($field, $field_2));
     $this->assertFalse(FieldStorageConfig::loadByName('entity_test', $field_storage->getName()));
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:37,代码来源:FieldCrudTest.php


示例19: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->fieldStorages = array();
     $this->entities = array();
     $this->entitiesByBundles = array();
     // Create two bundles.
     $this->bundles = array('bb_1' => 'bb_1', 'bb_2' => 'bb_2');
     foreach ($this->bundles as $name => $desc) {
         entity_test_create_bundle($name, $desc);
     }
     // Create two field storages.
     $field_storage = FieldStorageConfig::create(array('field_name' => 'bf_1', 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 1));
     $field_storage->save();
     $this->fieldStorages[] = $field_storage;
     $field_storage = FieldStorageConfig::create(array('field_name' => 'bf_2', 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 4));
     $field_storage->save();
     $this->fieldStorages[] = $field_storage;
     // For each bundle, create each field, and 10 entities with values for the
     // fields.
     foreach ($this->bundles as $bundle) {
         foreach ($this->fieldStorages as $field_storage) {
             FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $bundle])->save();
         }
         for ($i = 0; $i < 10; $i++) {
             $entity = $this->container->get('entity_type.manager')->getStorage($this->entityTypeId)->create(array('type' => $bundle));
             foreach ($this->fieldStorages as $field_storage) {
                 $entity->{$field_storage->getName()}->setValue($this->_generateTestFieldValues($field_storage->getCardinality()));
             }
             $entity->save();
         }
     }
     $this->entities = $this->container->get('entity_type.manager')->getStorage($this->entityTypeId)->loadMultiple();
     foreach ($this->entities as $entity) {
         // This test relies on the entities having stale field definitions
         // so that the deleted field can be accessed on them. Access the field
         // now, so that they are always loaded.
         $entity->bf_1->value;
         // Also keep track of the entities per bundle.
         $this->entitiesByBundles[$entity->bundle()][$entity->id()] = $entity;
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:42,代码来源:BulkDeleteTest.php


示例20: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->fieldStorages = array();
     $this->entities = array();
     $this->entities_by_bundles = array();
     // Create two bundles.
     $this->bundles = array('bb_1' => 'bb_1', 'bb_2' => 'bb_2');
     foreach ($this->bundles as $name => $desc) {
         entity_test_create_bundle($name, $desc);
     }
     // Create two field storages.
     $field_storage = entity_create('field_storage_config', array('field_name' => 'bf_1', 'entity_type' => $this->entity_type, 'type' => 'test_field', 'cardinality' => 1));
     $field_storage->save();
     $this->fieldStorages[] = $field_storage;
     $field_storage = entity_create('field_storage_config', array('field_name' => 'bf_2', 'entity_type' => $this->entity_type, 'type' => 'test_field', 'cardinality' => 4));
     $field_storage->save();
     $this->fieldStorages[] = $field_storage;
     // For each bundle, create each field, and 10 entities with values for the
     // fields.
     foreach ($this->bundles as $bundle) {
         foreach ($this->fieldStorages as $field_storage) {
             entity_create('field_config', array('field_storage' => $field_storage, 'bundle' => $bundle))->save();
         }
         for ($i = 0; $i < 10; $i++) {
             $entity = entity_create($this->entity_type, array('type' => $bundle));
             foreach ($this->fieldStorages as $field_storage) {
                 $entity->{$field_storage->getName()}->setValue($this->_generateTestFieldValues($field_storage->getCardinality()));
             }
             $entity->save();
         }
     }
     $this->entities = entity_load_multiple($this->entity_type);
     foreach ($this->entities as $entity) {
         // Also keep track of the entities per bundle.
         $this->entities_by_bundles[$entity->bundle()][$entity->id()] = $entity;
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:38,代码来源:BulkDeleteTest.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP entity_test_entity_types函数代码示例发布时间:2022-05-15
下一篇:
PHP entity_revision_load函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap