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

PHP entity_load函数代码示例

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

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



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

示例1: testFilterUI

 /**
  * Tests the filter UI.
  */
 public function testFilterUI()
 {
     $this->drupalGet('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid');
     $result = $this->xpath('//select[@id="edit-options-value"]/option');
     // Ensure that the expected hierarchy is available in the UI.
     $counter = 0;
     for ($i = 0; $i < 3; $i++) {
         for ($j = 0; $j <= $i; $j++) {
             $option = $result[$counter++];
             $prefix = $this->terms[$i][$j]->parent->target_id ? '-' : '';
             $attributes = $option->attributes();
             $tid = (string) $attributes->value;
             $this->assertEqual($prefix . $this->terms[$i][$j]->getName(), (string) $option);
             $this->assertEqual($this->terms[$i][$j]->id(), $tid);
         }
     }
     // Ensure the autocomplete input element appears when using the 'textfield'
     // type.
     $view = entity_load('view', 'test_filter_taxonomy_index_tid');
     $display =& $view->getDisplay('default');
     $display['display_options']['filters']['tid']['type'] = 'textfield';
     $view->save();
     $this->drupalGet('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid');
     $this->assertFieldByXPath('//input[@id="edit-options-value"]');
     // Tests \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid::calculateDependencies().
     $expected = ['config' => ['taxonomy.vocabulary.tags'], 'content' => ['taxonomy_term:tags:' . Term::load(2)->uuid()], 'module' => ['node', 'taxonomy', 'user']];
     $this->assertIdentical($expected, $view->calculateDependencies());
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:31,代码来源:TaxonomyIndexTidUiTest.php


示例2: testNodeCreation

 /**
  * Creates a "Basic page" node and verifies its consistency in the database.
  */
 function testNodeCreation()
 {
     // Test /node/add page with only one content type.
     entity_load('node_type', 'article')->delete();
     $this->drupalGet('node/add');
     $this->assertResponse(200);
     $this->assertUrl('node/add/page');
     // Create a node.
     $edit = array();
     $edit['title[0][value]'] = $this->randomMachineName(8);
     $edit['body[0][value]'] = $this->randomMachineName(16);
     $this->drupalPostForm('node/add/page', $edit, t('Save'));
     // Check that the Basic page has been created.
     $this->assertRaw(t('!post %title has been created.', array('!post' => 'Basic page', '%title' => $edit['title[0][value]'])), 'Basic page created.');
     // Check that the node exists in the database.
     $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
     $this->assertTrue($node, 'Node found in database.');
     // Verify that pages do not show submitted information by default.
     $this->drupalGet('node/' . $node->id());
     $this->assertNoText($node->getOwner()->getUsername());
     $this->assertNoText(format_date($node->getCreatedTime()));
     // Change the node type setting to show submitted by information.
     $node_type = entity_load('node_type', 'page');
     $node_type->setDisplaySubmitted(TRUE);
     $node_type->save();
     $this->drupalGet('node/' . $node->id());
     $this->assertText($node->getOwner()->getUsername());
     $this->assertText(format_date($node->getCreatedTime()));
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:32,代码来源:NodeCreationTest.php


示例3: testLoadingEntitiesCreatedInBatch

 /**
  * Tests loading entities created in a batch in simpletest_test_install().
  */
 public function testLoadingEntitiesCreatedInBatch()
 {
     $entity1 = entity_load('entity_test', 1);
     $this->assertNotNull($entity1, 'Successfully loaded entity 1.');
     $entity2 = entity_load('entity_test', 2);
     $this->assertNotNull($entity2, 'Successfully loaded entity 2.');
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:SimpleTestInstallBatchTest.php


示例4: testTaxonomyTermHierarchy

 /**
  * Test terms in a single and multiple hierarchy.
  */
 function testTaxonomyTermHierarchy()
 {
     // Create two taxonomy terms.
     $term1 = $this->createTerm($this->vocabulary);
     $term2 = $this->createTerm($this->vocabulary);
     // Check that hierarchy is flat.
     $vocabulary = entity_load('taxonomy_vocabulary', $this->vocabulary->id());
     $this->assertEqual(0, $vocabulary->hierarchy, 'Vocabulary is flat.');
     // Edit $term2, setting $term1 as parent.
     $edit = array();
     $edit['parent[]'] = array($term1->id());
     $this->drupalPostForm('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save'));
     // Check the hierarchy.
     $children = taxonomy_term_load_children($term1->id());
     $parents = taxonomy_term_load_parents($term2->id());
     $this->assertTrue(isset($children[$term2->id()]), 'Child found correctly.');
     $this->assertTrue(isset($parents[$term1->id()]), 'Parent found correctly.');
     // Load and save a term, confirming that parents are still set.
     $term = Term::load($term2->id());
     $term->save();
     $parents = taxonomy_term_load_parents($term2->id());
     $this->assertTrue(isset($parents[$term1->id()]), 'Parent found correctly.');
     // Create a third term and save this as a parent of term2.
     $term3 = $this->createTerm($this->vocabulary);
     $term2->parent = array($term1->id(), $term3->id());
     $term2->save();
     $parents = taxonomy_term_load_parents($term2->id());
     $this->assertTrue(isset($parents[$term1->id()]) && isset($parents[$term3->id()]), 'Both parents found successfully.');
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:32,代码来源:TermTest.php


示例5: testFiles

 /**
  * Tests the Drupal 6 files to Drupal 8 migration.
  */
 public function testFiles()
 {
     /** @var \Drupal\file\FileInterface $file */
     $file = entity_load('file', 1);
     $this->assertIdentical('Image1.png', $file->getFilename());
     $this->assertIdentical('39325', $file->getSize());
     $this->assertIdentical('public://image-1.png', $file->getFileUri());
     $this->assertIdentical('image/png', $file->getMimeType());
     // It is pointless to run the second half from MigrateDrupal6Test.
     if (empty($this->standalone)) {
         return;
     }
     // Test that we can re-import and also test with file_directory_path set.
     db_truncate(entity_load('migration', 'd6_file')->getIdMap()->mapTableName())->execute();
     $migration = entity_load_unchanged('migration', 'd6_file');
     $dumps = array($this->getDumpDirectory() . '/Variable.php');
     $this->prepare($migration, $dumps);
     // Update the file_directory_path.
     Database::getConnection('default', 'migrate')->update('variable')->fields(array('value' => serialize('files/test')))->condition('name', 'file_directory_path')->execute();
     Database::getConnection('default', 'migrate')->update('variable')->fields(array('value' => serialize($this->getTempFilesDirectory())))->condition('name', 'file_directory_temp')->execute();
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     $file = entity_load('file', 2);
     $this->assertIdentical('public://core/modules/simpletest/files/image-2.jpg', $file->getFileUri());
     // Ensure that a temporary file has been migrated.
     $file = entity_load('file', 6);
     $this->assertIdentical('temporary://' . static::getUniqueFilename(), $file->getFileUri());
 }
开发者ID:dev981,项目名称:gaptest,代码行数:31,代码来源:MigrateFileTest.php


示例6: testCacheTags

 /**
  * Tests the bubbling of cache tags.
  */
 public function testCacheTags()
 {
     // Create the entity that will be commented upon.
     $commented_entity = entity_create('entity_test', array('name' => $this->randomMachineName()));
     $commented_entity->save();
     // Verify cache tags on the rendered entity before it has comments.
     $build = \Drupal::entityManager()->getViewBuilder('entity_test')->view($commented_entity);
     drupal_render($build);
     $expected_cache_tags = array('entity_test_view', 'entity_test:' . $commented_entity->id(), 'comment_list');
     sort($expected_cache_tags);
     $this->assertEqual($build['#cache']['tags'], $expected_cache_tags, 'The test entity has the expected cache tags before it has comments.');
     // Create a comment on that entity. Comment loading requires that the uid
     // also exists in the {users} table.
     $user = $this->createUser();
     $user->save();
     $comment = entity_create('comment', array('subject' => 'Llama', 'comment_body' => array('value' => 'Llamas are cool!', 'format' => 'plain_text'), 'entity_id' => $commented_entity->id(), 'entity_type' => 'entity_test', 'field_name' => 'comment', 'comment_type' => 'comment', 'status' => CommentInterface::PUBLISHED, 'uid' => $user->id()));
     $comment->save();
     // Load commented entity so comment_count gets computed.
     // @todo Remove the $reset = TRUE parameter after
     //   https://www.drupal.org/node/597236 lands. It's a temporary work-around.
     $commented_entity = entity_load('entity_test', $commented_entity->id(), TRUE);
     // Verify cache tags on the rendered entity when it has comments.
     $build = \Drupal::entityManager()->getViewBuilder('entity_test')->view($commented_entity);
     drupal_render($build);
     $expected_cache_tags = array('entity_test_view', 'entity_test:' . $commented_entity->id(), 'comment_list', 'comment_view', 'comment:' . $comment->id(), 'config:filter.format.plain_text', 'user_view', 'user:2');
     sort($expected_cache_tags);
     $this->assertEqual($build['#cache']['tags'], $expected_cache_tags, 'The test entity has the expected cache tags when it has comments.');
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:31,代码来源:CommentDefaultFormatterCacheTagsTest.php


示例7: 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


示例8: testRecreateEntity

 public function testRecreateEntity()
 {
     $type_name = Unicode::strtolower($this->randomMachineName(16));
     $content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type one'));
     $content_type->save();
     /** @var \Drupal\Core\Config\StorageInterface $active */
     $active = $this->container->get('config.storage');
     /** @var \Drupal\Core\Config\StorageInterface $staging */
     $staging = $this->container->get('config.storage.staging');
     $config_name = $content_type->getEntityType()->getConfigPrefix() . '.' . $content_type->id();
     $this->copyConfig($active, $staging);
     // Delete the content type. This will also delete a field storage, a field,
     // an entity view display and an entity form display.
     $content_type->delete();
     $this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.');
     // Recreate with the same type - this will have a different UUID.
     $content_type = entity_create('node_type', array('type' => $type_name, 'name' => 'Node type two'));
     $content_type->save();
     $this->configImporter->reset();
     // A node type, a field storage, a field, an entity view display and an
     // entity form display will be recreated.
     $creates = $this->configImporter->getUnprocessedConfiguration('create');
     $deletes = $this->configImporter->getUnprocessedConfiguration('delete');
     $this->assertEqual(5, count($creates), 'There are 5 configuration items to create.');
     $this->assertEqual(5, count($deletes), 'There are 5 configuration items to delete.');
     $this->assertEqual(0, count($this->configImporter->getUnprocessedConfiguration('update')), 'There are no configuration items to update.');
     $this->assertIdentical($creates, array_reverse($deletes), 'Deletes and creates contain the same configuration names in opposite orders due to dependencies.');
     $this->configImporter->import();
     // Verify that there is nothing more to import.
     $this->assertFalse($this->configImporter->reset()->hasUnprocessedConfigurationChanges());
     $content_type = entity_load('node_type', $type_name);
     $this->assertEqual('Node type one', $content_type->label());
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:33,代码来源:ConfigImportRecreateTest.php


示例9: testShapeItem

 /**
  * Tests using entity fields of the field field type.
  */
 public function testShapeItem()
 {
     // Verify entity creation.
     $entity = EntityTest::create();
     $shape = 'cube';
     $color = 'blue';
     $entity->{$this->fieldName}->shape = $shape;
     $entity->{$this->fieldName}->color = $color;
     $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}->shape, $shape);
     $this->assertEqual($entity->{$this->fieldName}->color, $color);
     $this->assertEqual($entity->{$this->fieldName}[0]->shape, $shape);
     $this->assertEqual($entity->{$this->fieldName}[0]->color, $color);
     // Verify changing the field value.
     $new_shape = 'circle';
     $new_color = 'red';
     $entity->{$this->fieldName}->shape = $new_shape;
     $entity->{$this->fieldName}->color = $new_color;
     $this->assertEqual($entity->{$this->fieldName}->shape, $new_shape);
     $this->assertEqual($entity->{$this->fieldName}->color, $new_color);
     // Read changed entity and assert changed values.
     $entity->save();
     $entity = entity_load('entity_test', $id);
     $this->assertEqual($entity->{$this->fieldName}->shape, $new_shape);
     $this->assertEqual($entity->{$this->fieldName}->color, $new_color);
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:35,代码来源:ShapeItemTest.php


示例10: processCallback

 /**
  * Callback for preg_replace in process()
  */
 public static function processCallback($matches = array())
 {
     $content = '';
     $entity_type = $entity_id = $view_mode = '';
     foreach ($matches as $key => $match) {
         switch ($key) {
             case 1:
                 $entity_type = $match;
                 break;
             case 2:
                 $entity_id = $match;
                 break;
             case 3:
                 $view_mode = $match;
                 break;
         }
     }
     $entities = entity_load($entity_type, array($entity_id));
     if (!empty($entities)) {
         $render_array = entity_view($entity_type, $entities, $view_mode, NULL, TRUE);
         // Remove contextual links.
         if (isset($render_array[$entity_type][$entity_id]['#contextual_links'])) {
             unset($render_array[$entity_type][$entity_id]['#contextual_links']);
         }
         $content = render($render_array);
     }
     return $content;
 }
开发者ID:rafavergara,项目名称:ddv8,代码行数:31,代码来源:FilterMailchimpCampaign.php


示例11: testUserRole

 /**
  * Tests user role migration.
  */
 public function testUserRole()
 {
     /** @var \Drupal\migrate\entity\Migration $migration */
     $migration = entity_load('migration', 'd6_user_role');
     $rid = 'anonymous';
     $anonymous = Role::load($rid);
     $this->assertIdentical($rid, $anonymous->id());
     $this->assertIdentical(array('migrate test anonymous permission', 'use text format filtered_html'), $anonymous->getPermissions());
     $this->assertIdentical(array($rid), $migration->getIdMap()->lookupDestinationId(array(1)));
     $rid = 'authenticated';
     $authenticated = Role::load($rid);
     $this->assertIdentical($rid, $authenticated->id());
     $this->assertIdentical(array('migrate test authenticated permission', 'use text format filtered_html'), $authenticated->getPermissions());
     $this->assertIdentical(array($rid), $migration->getIdMap()->lookupDestinationId(array(2)));
     $rid = 'migrate_test_role_1';
     $migrate_test_role_1 = Role::load($rid);
     $this->assertIdentical($rid, $migrate_test_role_1->id());
     $this->assertIdentical(array(0 => 'migrate test role 1 test permission', 'use text format full_html'), $migrate_test_role_1->getPermissions());
     $this->assertIdentical(array($rid), $migration->getIdMap()->lookupDestinationId(array(3)));
     $rid = 'migrate_test_role_2';
     $migrate_test_role_2 = Role::load($rid);
     $this->assertIdentical(array('migrate test role 2 test permission', 'use PHP for settings', 'administer contact forms', 'skip comment approval', 'edit own blog content', 'edit any blog content', 'delete own blog content', 'delete any blog content', 'create forum content', 'delete any forum content', 'delete own forum content', 'edit any forum content', 'edit own forum content', 'administer nodes', 'access content overview'), $migrate_test_role_2->getPermissions());
     $this->assertIdentical($rid, $migrate_test_role_2->id());
     $this->assertIdentical(array($rid), $migration->getIdMap()->lookupDestinationId(array(4)));
     $rid = 'migrate_test_role_3_that_is_long';
     $migrate_test_role_3 = Role::load($rid);
     $this->assertIdentical($rid, $migrate_test_role_3->id());
     $this->assertIdentical(array($rid), $migration->getIdMap()->lookupDestinationId(array(5)));
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:32,代码来源:MigrateUserRoleTest.php


示例12: testCrudAndUpdate

 /**
  * Tests processed properties.
  */
 public function testCrudAndUpdate()
 {
     $entity_type = 'entity_test';
     $this->createField($entity_type);
     // Create an entity with a summary and no text format.
     $entity = entity_create($entity_type);
     $entity->summary_field->value = $value = $this->randomMachineName();
     $entity->summary_field->summary = $summary = $this->randomMachineName();
     $entity->summary_field->format = NULL;
     $entity->name->value = $this->randomMachineName();
     $entity->save();
     $entity = entity_load($entity_type, $entity->id());
     $this->assertTrue($entity->summary_field instanceof FieldItemListInterface, 'Field implements interface.');
     $this->assertTrue($entity->summary_field[0] instanceof FieldItemInterface, 'Field item implements interface.');
     $this->assertEqual($entity->summary_field->value, $value);
     $this->assertEqual($entity->summary_field->summary, $summary);
     $this->assertNull($entity->summary_field->format);
     // Even if no format is given, if text processing is enabled, the default
     // format is used.
     $this->assertEqual($entity->summary_field->processed, "<p>{$value}</p>\n");
     $this->assertEqual($entity->summary_field->summary_processed, "<p>{$summary}</p>\n");
     // Change the format, this should update the processed properties.
     $entity->summary_field->format = 'no_filters';
     $this->assertEqual($entity->summary_field->processed, $value);
     $this->assertEqual($entity->summary_field->summary_processed, $summary);
     // Test the generateSampleValue() method.
     $entity = entity_create($entity_type);
     $entity->summary_field->generateSampleItems();
     $this->entityValidateAndSave($entity);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:33,代码来源:TextWithSummaryItemTest.php


示例13: setUp

 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     if ($this->profile != 'standard') {
         $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page', 'settings' => array('node' => array('options' => array('promote' => FALSE), 'submitted' => FALSE))));
         $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
     }
     $this->admin_user = $this->drupalCreateUser(array('administer nodes', 'bypass node access', 'administer content types', 'administer xmlsitemap', 'administer taxonomy'));
     $this->normal_user = $this->drupalCreateUser(array('create page content', 'edit any page content', 'access content', 'view own unpublished content'));
     // allow anonymous user to view user profiles
     $user_role = entity_load('user_role', DRUPAL_ANONYMOUS_RID);
     $user_role->grantPermission('access content');
     $user_role->save();
     xmlsitemap_link_bundle_enable('node', 'article');
     xmlsitemap_link_bundle_enable('node', 'page');
     $this->config->set('xmlsitemap_entity_taxonomy_vocabulary', 1);
     $this->config->set('xmlsitemap_entity_taxonomy_term', 1);
     $this->config->save();
     xmlsitemap_link_bundle_settings_save('node', 'page', array('status' => 1, 'priority' => 0.6, 'changefreq' => XMLSITEMAP_FREQUENCY_WEEKLY));
     // Add a vocabulary so we can test different view modes.
     $vocabulary = entity_create('taxonomy_vocabulary', array('name' => 'Tags', 'description' => $this->randomMachineName(), 'vid' => 'tags', 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 'help' => ''));
     $vocabulary->save();
     xmlsitemap_link_bundle_enable('taxonomy_term', 'tags');
     // Set up a field and instance.
     $field_name = 'tags';
     entity_create('field_storage_config', array('name' => $field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'settings' => array('allowed_values' => array(array('vocabulary' => $vocabulary->vid, 'parent' => '0'))), 'cardinality' => '-1'))->save();
     entity_create('field_instance_config', array('field_name' => $field_name, 'entity_type' => 'node', 'bundle' => 'page'))->save();
     entity_get_form_display('node', 'page', 'default')->setComponent($field_name, array('type' => 'taxonomy_autocomplete'))->save();
     // Show on default display and teaser.
     entity_get_display('node', 'page', 'default')->setComponent($field_name, array('type' => 'taxonomy_term_reference_link'))->save();
     entity_get_display('node', 'page', 'teaser')->setComponent($field_name, array('type' => 'taxonomy_term_reference_link'))->save();
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:35,代码来源:XmlSitemapNodeFunctionalTest.php


示例14: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('node');
     $this->installConfig(['node']);
     $this->installSchema('node', ['node_access']);
     $this->installSchema('system', ['sequences']);
     // Create a new user which needs to have UID 1, because that is expected by
     // the assertions from
     // \Drupal\migrate_drupal\Tests\d6\MigrateNodeRevisionTest.
     User::create(['uid' => 1, 'name' => $this->randomMachineName(), 'status' => 1])->enforceIsNew(TRUE)->save();
     $node_type = entity_create('node_type', array('type' => 'test_planet'));
     $node_type->save();
     node_add_body_field($node_type);
     $node_type = entity_create('node_type', array('type' => 'story'));
     $node_type->save();
     node_add_body_field($node_type);
     $id_mappings = array('d6_node_type' => array(array(array('test_story'), array('story'))), 'd6_filter_format' => array(array(array(1), array('filtered_html')), array(array(2), array('full_html'))), 'd6_user' => array(array(array(1), array(1)), array(array(2), array(2))), 'd6_field_instance_widget_settings' => array(array(array('page', 'field_test'), array('node', 'page', 'default', 'test'))), 'd6_field_formatter_settings' => array(array(array('page', 'default', 'node', 'field_test'), array('node', 'page', 'default', 'field_test'))));
     $this->prepareMigrations($id_mappings);
     $migration = entity_load('migration', 'd6_node_settings');
     $migration->setMigrationResult(MigrationInterface::RESULT_COMPLETED);
     // Create a test node.
     $node = entity_create('node', array('type' => 'story', 'nid' => 1, 'vid' => 1, 'revision_log' => '', 'title' => $this->randomString()));
     $node->enforceIsNew();
     $node->save();
     $node = entity_create('node', array('type' => 'test_planet', 'nid' => 3, 'vid' => 4, 'revision_log' => '', 'title' => $this->randomString()));
     $node->enforceIsNew();
     $node->save();
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:32,代码来源:MigrateNodeTestBase.php


示例15: testFactoryService

 /**
  * Tests the views.executable container service.
  */
 public function testFactoryService()
 {
     $factory = $this->container->get('views.executable');
     $this->assertTrue($factory instanceof ViewExecutableFactory, 'A ViewExecutableFactory instance was returned from the container.');
     $view = entity_load('view', 'test_executable_displays');
     $this->assertTrue($factory->get($view) instanceof ViewExecutable, 'A ViewExecutable instance was returned from the factory.');
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:10,代码来源:ViewExecutableTest.php


示例16: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $elements = array();
     $files = $this->getEntitiesToView($items, $langcode);
     // Early opt-out if the field is empty.
     if (empty($files)) {
         return $elements;
     }
     $image_style_setting = $this->getSetting('image_style');
     // Determine if Image style is required.
     $image_style = NULL;
     if (!empty($image_style_setting)) {
         $image_style = entity_load('image_style', $image_style_setting);
     }
     foreach ($files as $delta => $file) {
         $image_uri = $file->getFileUri();
         // Get image style URL
         if ($image_style) {
             $image_uri = ImageStyle::load($image_style->getName())->buildUrl($image_uri);
         } else {
             // Get absolute path for original image
             $image_uri = $file->url();
         }
         $elements[$delta] = array('#markup' => $image_uri);
     }
     return $elements;
 }
开发者ID:joesb,项目名称:image_raw_formatter,代码行数:30,代码来源:ImageRawFormatter.php


示例17: testMenuLinks

 public function testMenuLinks()
 {
     $menu_link = entity_load('menu_link_content', 138);
     $this->assertIdentical('Test 1', $menu_link->getTitle());
     $this->assertIdentical('secondary-links', $menu_link->getMenuName());
     $this->assertIdentical('Test menu link 1', $menu_link->getDescription());
     $this->assertIdentical(TRUE, $menu_link->isEnabled());
     $this->assertIdentical(FALSE, $menu_link->isExpanded());
     $this->assertIdentical(['attributes' => ['title' => 'Test menu link 1']], $menu_link->link->options);
     $this->assertIdentical('internal:/user/login', $menu_link->link->uri);
     $this->assertIdentical(15, $menu_link->getWeight());
     $menu_link = entity_load('menu_link_content', 139);
     $this->assertIdentical('Test 2', $menu_link->getTitle());
     $this->assertIdentical('secondary-links', $menu_link->getMenuName());
     $this->assertIdentical('Test menu link 2', $menu_link->getDescription());
     $this->assertIdentical(TRUE, $menu_link->isEnabled());
     $this->assertIdentical(TRUE, $menu_link->isExpanded());
     $this->assertIdentical(['query' => 'foo=bar', 'attributes' => ['title' => 'Test menu link 2']], $menu_link->link->options);
     $this->assertIdentical('internal:/admin', $menu_link->link->uri);
     $this->assertIdentical(12, $menu_link->getWeight());
     $menu_link = entity_load('menu_link_content', 140);
     $this->assertIdentical('Drupal.org', $menu_link->getTitle());
     $this->assertIdentical('secondary-links', $menu_link->getMenuName());
     $this->assertIdentical('', $menu_link->getDescription());
     $this->assertIdentical(TRUE, $menu_link->isEnabled());
     $this->assertIdentical(FALSE, $menu_link->isExpanded());
     $this->assertIdentical(['attributes' => ['title' => '']], $menu_link->link->options);
     $this->assertIdentical('https://www.drupal.org', $menu_link->link->uri);
     $this->assertIdentical(0, $menu_link->getWeight());
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:30,代码来源:MigrateMenuLinkTest.php


示例18: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Create some fields so the data gets stored.
     entity_create('field_storage_config', array('entity_type' => 'user', 'field_name' => 'profile_color', 'type' => 'text'))->save();
     entity_create('field_storage_config', array('entity_type' => 'user', 'field_name' => 'profile_biography', 'type' => 'text_long'))->save();
     entity_create('field_storage_config', array('entity_type' => 'user', 'field_name' => 'profile_sell_address', 'type' => 'boolean'))->save();
     entity_create('field_storage_config', array('entity_type' => 'user', 'field_name' => 'profile_sold_to', 'type' => 'list_string', 'settings' => array('allowed_values' => array('Pill spammers' => 'Pill spammers', 'Fitness spammers' => 'Fitness spammers'))))->save();
     entity_create('field_storage_config', array('entity_type' => 'user', 'field_name' => 'profile_bands', 'type' => 'text', 'cardinality' => -1))->save();
     entity_create('field_storage_config', array('entity_type' => 'user', 'field_name' => 'profile_blog', 'type' => 'link'))->save();
     entity_create('field_storage_config', array('entity_type' => 'user', 'field_name' => 'profile_birthdate', 'type' => 'datetime'))->save();
     entity_create('field_storage_config', array('entity_type' => 'user', 'field_name' => 'profile_love_migrations', 'type' => 'boolean'))->save();
     // Create the field instances.
     foreach (Drupal6UserProfileFields::getData('profile_fields') as $field) {
         entity_create('field_config', array('label' => $field['title'], 'description' => '', 'field_name' => $field['name'], 'entity_type' => 'user', 'bundle' => 'user', 'required' => 0))->save();
     }
     // Create some users to migrate the profile data to.
     foreach (Drupal6User::getData('users') as $u) {
         $user = entity_create('user', $u);
         $user->enforceIsNew();
         $user->save();
     }
     // Add some id mappings for the dependant migrations.
     $id_mappings = array('d6_user_profile_field_instance' => array(array(array(1), array('user', 'user', 'fieldname'))), 'd6_user_profile_entity_display' => array(array(array(1), array('user', 'user', 'default', 'fieldname'))), 'd6_user_profile_entity_form_display' => array(array(array(1), array('user', 'user', 'default', 'fieldname'))), 'd6_user' => array(array(array(2), array(2)), array(array(8), array(8)), array(array(15), array(15))));
     $this->prepareMigrations($id_mappings);
     // Load database dumps to provide source data.
     $dumps = array($this->getDumpDirectory() . '/Drupal6UserProfileFields.php', $this->getDumpDirectory() . '/Drupal6User.php');
     $this->loadDumps($dumps);
     // Migrate profile fields.
     $migration_format = entity_load('migration', 'd6_profile_values:user');
     $executable = new MigrateExecutable($migration_format, $this);
     $executable->import();
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:36,代码来源:MigrateUserProfileValuesTest.php


示例19: setUp

 protected function setUp()
 {
     parent::setUp();
     node_access_test_add_field(entity_load('node_type', 'article'));
     node_access_rebuild();
     \Drupal::state()->set('node_access_test.private', TRUE);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:7,代码来源:FilePrivateTest.php


示例20: testTestItem

 /**
  * Tests using entity fields of the geolocation field type.
  */
 public function testTestItem()
 {
     // Verify entity creation.
     $entity = entity_create('entity_test');
     $entity->name->value = $this->randomMachineName();
     $lat = '49.880657';
     $lng = '10.869212';
     $entity->field_test->lat = $lat;
     $entity->field_test->lng = $lng;
     $entity->save();
     // Verify entity has been created properly.
     $id = $entity->id();
     $entity = entity_load('entity_test', $id);
     $this->assertTrue($entity->field_test instanceof FieldItemListInterface, 'Field implements interface.');
     $this->assertTrue($entity->field_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
     $this->assertEqual($entity->field_test->lat, $lat, "Lat {$entity->field_test->lat} is equal to lat {$lat}.");
     $this->assertEqual($entity->field_test[0]->lat, $lat, "Lat {$entity->field_test[0]->lat} is equal to lat {$lat}.");
     $this->assertEqual($entity->field_test->lng, $lng, "Lng {$entity->field_test->lng} is equal to lng {$lng}.");
     $this->assertEqual($entity->field_test[0]->lng, $lng, "Lng {$entity->field_test[0]->lng} is equal to lng {$lng}.");
     // Verify changing the field value.
     $new_lat = rand(-90, 90) - rand(0, 999999) / 1000000;
     $new_lng = rand(-180, 180) - rand(0, 999999) / 1000000;
     $entity->field_test->lat = $new_lat;
     $entity->field_test->lng = $new_lng;
     $this->assertEqual($entity->field_test->lat, $new_lat, "Lat {$entity->field_test->lat} is equal to new lat {$new_lat}.");
     $this->assertEqual($entity->field_test->lng, $new_lng, "Lng {$entity->field_test->lng} is equal to new lng {$new_lng}.");
     // Read changed entity and assert changed values.
     $entity->save();
     $entity = entity_load('entity_test', $id);
     $this->assertEqual($entity->field_test->lat, $new_lat, "Lat {$entity->field_test->lat} is equal to new lat {$new_lat}.");
     $this->assertEqual($entity->field_test->lng, $new_lng, "Lng {$entity->field_test->lng} is equal to new lng {$new_lng}.");
 }
开发者ID:pedrocones,项目名称:geolocation,代码行数:35,代码来源:GeolocationItemTest.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP entity_load_multiple函数代码示例发布时间:2022-05-15
下一篇:
PHP entity_link函数代码示例发布时间: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