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


PHP FieldConfig::load方法代码示例

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


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

示例1: testUserProfileFields

 /**
  * Tests migration of user profile fields.
  */
 public function testUserProfileFields()
 {
     // Migrated a text field.
     $field = FieldConfig::load('user.user.profile_color');
     $this->assertIdentical('Favorite color', $field->label());
     $this->assertIdentical('List your favorite color', $field->getDescription());
     // Migrated a textarea.
     $field = FieldConfig::load('user.user.profile_biography');
     $this->assertIdentical('Biography', $field->label());
     $this->assertIdentical('Tell people a little bit about yourself', $field->getDescription());
     // Migrated checkbox field.
     $field = FieldConfig::load('user.user.profile_sell_address');
     $this->assertIdentical('Sell your email address?', $field->label());
     $this->assertIdentical("If you check this box, we'll sell your address to spammers to help line the pockets of our shareholders. Thanks!", $field->getDescription());
     // Migrated selection field.
     $field = FieldConfig::load('user.user.profile_sold_to');
     $this->assertIdentical('Sales Category', $field->label());
     $this->assertIdentical("Select the sales categories to which this user's address was sold.", $field->getDescription());
     // Migrated list field.
     $field = FieldConfig::load('user.user.profile_bands');
     $this->assertIdentical('Favorite bands', $field->label());
     $this->assertIdentical("Enter your favorite bands. When you've saved your profile, you'll be able to find other people with the same favorites.", $field->getDescription());
     // Migrated URL field.
     $field = FieldConfig::load('user.user.profile_blog');
     $this->assertIdentical('Blog', $field->label());
     $this->assertIdentical("Paste the full URL, including http://, of your personal blog.", $field->getDescription());
     // Migrated date field.
     $field = FieldConfig::load('user.user.profile_birthdate');
     $this->assertIdentical('Birthdate', $field->label());
     $this->assertIdentical("Enter your birth date and we'll send you a coupon.", $field->getDescription());
     // Another migrated checkbox field, with a different source visibility setting.
     $field = FieldConfig::load('user.user.profile_love_migrations');
     $this->assertIdentical('I love migrations', $field->label());
     $this->assertIdentical("If you check this box, you love migrations.", $field->getDescription());
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:38,代码来源:MigrateUserProfileFieldInstanceTest.php

示例2: testCommentDefaultFields

 /**
  * Tests that the default 'comment_body' field is correctly added.
  */
 function testCommentDefaultFields()
 {
     // Do not make assumptions on default node types created by the test
     // installation profile, and create our own.
     $this->drupalCreateContentType(array('type' => 'test_node_type'));
     $this->addDefaultCommentField('node', 'test_node_type');
     // Check that the 'comment_body' field is present on the comment bundle.
     $field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
     $this->assertTrue(!empty($field), 'The comment_body field is added when a comment bundle is created');
     $field->delete();
     // Check that the 'comment_body' field is not deleted since it is persisted
     // even if it has no fields.
     $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
     $this->assertTrue($field_storage, 'The comment_body field storage was not deleted');
     // Create a new content type.
     $type_name = 'test_node_type_2';
     $this->drupalCreateContentType(array('type' => $type_name));
     $this->addDefaultCommentField('node', $type_name);
     // Check that the 'comment_body' field exists and has an instance on the
     // new comment bundle.
     $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
     $this->assertTrue($field_storage, 'The comment_body field exists');
     $field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
     $this->assertTrue(isset($field), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
     // Test adding a field that defaults to CommentItemInterface::CLOSED.
     $this->addDefaultCommentField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED, 'who_likes_ponies');
     $field = FieldConfig::load('node.test_node_type.who_likes_ponies');
     $this->assertEqual($field->getDefaultValueLiteral()[0]['status'], CommentItemInterface::CLOSED);
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:32,代码来源:CommentFieldsTest.php

示例3: testWidget

 /**
  * Tests the widget.
  */
 protected function testWidget()
 {
     $user = $this->drupalCreateUser(['administer user fields']);
     $this->drupalLogin($user);
     // Test the widget when setting a default field value.
     $field_name = strtolower($this->randomMachineName());
     $selectable_plugin_type_id = 'block';
     $field_type = 'plugin:' . $selectable_plugin_type_id;
     $default_selected_plugin_id = 'broken';
     $this->drupalPostForm('admin/config/people/accounts/fields/add-field', ['label' => $this->randomString(), 'field_name' => $field_name, 'new_storage_type' => $field_type], t('Save and continue'));
     $this->drupalPostForm(NULL, [], t('Save field settings'));
     $this->drupalPostForm(NULL, [sprintf('default_value_input[field_%s][0][plugin_selector][container][select][container][plugin_id]', $field_name) => $default_selected_plugin_id], t('Choose'));
     $this->drupalPostForm(NULL, [], t('Save settings'));
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     // Get all plugin fields.
     $field_storage_id = 'user.field_' . $field_name;
     $field_storage = FieldStorageConfig::load($field_storage_id);
     $this->assertNotNull($field_storage);
     $field_id = 'user.user.field_' . $field_name;
     /** @var \Drupal\field\FieldConfigInterface $field */
     $field = FieldConfig::load($field_id);
     $this->assertNotNull($field);
     $this->assertEqual($field->getDefaultValueLiteral()[0]['plugin_type_id'], $selectable_plugin_type_id);
     $this->assertEqual($field->getDefaultValueLiteral()[0]['plugin_id'], $default_selected_plugin_id);
     $this->assertTrue(is_array($field->getDefaultValueLiteral()[0]['plugin_configuration']));
     // Test the widget when creating an entity.
     $entity_selected_plugin_id = 'system_breadcrumb_block';
     $this->drupalPostForm('user/' . $user->id() . '/edit', [sprintf('field_%s[0][plugin_selector][container][select][container][plugin_id]', $field_name) => $entity_selected_plugin_id], t('Choose'));
     $this->drupalPostForm(NULL, [], t('Save'));
     // Test whether the widget displays field values.
     /** @var \Drupal\Core\Entity\ContentEntityInterface $user */
     $user = entity_load_unchanged('user', $user->id());
     $this->assertEqual($user->get('field_' . $field_name)->get(0)->get('plugin_type_id')->getValue(), $selectable_plugin_type_id);
     $this->assertEqual($user->get('field_' . $field_name)->get(0)->get('plugin_id')->getValue(), $entity_selected_plugin_id);
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:38,代码来源:PluginSelectorTest.php

示例4: testUserPictureField

 /**
  * Test the user picture field migration.
  */
 public function testUserPictureField()
 {
     /** @var \Drupal\field\FieldConfigInterface $field */
     $field = FieldConfig::load('user.user.user_picture');
     $this->assertTrue($field instanceof FieldConfigInterface);
     $this->assertIdentical('user', $field->getTargetEntityTypeId());
     $this->assertIdentical('user', $field->getTargetBundle());
     $this->assertIdentical('user_picture', $field->getName());
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:12,代码来源:MigrateUserPictureFieldInstanceTest.php

示例5: testFileItem

 /**
  * Tests using entity fields of the file field type.
  */
 public function testFileItem()
 {
     // Check that the selection handler was automatically assigned to
     // 'default:file'.
     $field_definition = FieldConfig::load('entity_test.entity_test.file_test');
     $handler_id = $field_definition->getSetting('handler');
     $this->assertEqual($handler_id, 'default:file');
     // Create a test entity with the
     $entity = EntityTest::create();
     $entity->file_test->target_id = $this->file->id();
     $entity->file_test->display = 1;
     $entity->file_test->description = $description = $this->randomMachineName();
     $entity->name->value = $this->randomMachineName();
     $entity->save();
     $entity = EntityTest::load($entity->id());
     $this->assertTrue($entity->file_test instanceof FieldItemListInterface, 'Field implements interface.');
     $this->assertTrue($entity->file_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
     $this->assertEqual($entity->file_test->target_id, $this->file->id());
     $this->assertEqual($entity->file_test->display, 1);
     $this->assertEqual($entity->file_test->description, $description);
     $this->assertEqual($entity->file_test->entity->getFileUri(), $this->file->getFileUri());
     $this->assertEqual($entity->file_test->entity->url(), $url = file_create_url($this->file->getFileUri()));
     $this->assertEqual($entity->file_test->entity->id(), $this->file->id());
     $this->assertEqual($entity->file_test->entity->uuid(), $this->file->uuid());
     // Make sure the computed files reflects updates to the file.
     file_put_contents('public://example-2.txt', $this->randomMachineName());
     $file2 = File::create(['uri' => 'public://example-2.txt']);
     $file2->save();
     $entity->file_test->target_id = $file2->id();
     $this->assertEqual($entity->file_test->entity->id(), $file2->id());
     $this->assertEqual($entity->file_test->entity->getFileUri(), $file2->getFileUri());
     // Test the deletion of an entity having an entity reference field targeting
     // a non-existing entity.
     $file2->delete();
     $entity->delete();
     // Test the generateSampleValue() method.
     $entity = EntityTest::create();
     $entity->file_test->generateSampleItems();
     $this->entityValidateAndSave($entity);
     // Verify that the sample file was stored in the correct directory.
     $uri = $entity->file_test->entity->getFileUri();
     $this->assertEqual($this->directory, dirname(file_uri_target($uri)));
     // Make sure the computed files reflects updates to the file.
     file_put_contents('public://example-3.txt', $this->randomMachineName());
     // Test unsaved file entity.
     $file3 = File::create(['uri' => 'public://example-3.txt']);
     $display = entity_get_display('entity_test', 'entity_test', 'default');
     $display->setComponent('file_test', ['label' => 'above', 'type' => 'file_default', 'weight' => 1])->save();
     $entity = EntityTest::create();
     $entity->file_test = array('entity' => $file3);
     $uri = $file3->getFileUri();
     $output = entity_view($entity, 'default');
     \Drupal::service('renderer')->renderRoot($output);
     $this->assertTrue(!empty($entity->file_test->entity));
     $this->assertEqual($entity->file_test->entity->getFileUri(), $uri);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:59,代码来源:FileItemTest.php

示例6: buildForm

 /**
  * {@inheritdoc}
  *
  * @param string $field_config
  *   The ID of the field config whose field storage config is being edited.
  */
 public function buildForm(array $form, FormStateInterface $form_state, $field_config = NULL)
 {
     if ($field_config) {
         $field = FieldConfig::load($field_config);
         $form_state->set('field_config', $field);
         $form_state->set('entity_type_id', $field->getTargetEntityTypeId());
         $form_state->set('bundle', $field->getTargetBundle());
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:neetumorwani,项目名称:blogging,代码行数:16,代码来源:FieldStorageConfigEditForm.php

示例7: testMigrateFieldIntoUnknownNodeType

 /**
  * Tests migrating fields into non-existent content types.
  */
 public function testMigrateFieldIntoUnknownNodeType()
 {
     $this->sourceDatabase->delete('node_type')->condition('type', 'test_planet')->execute();
     // The field migrations use the migration plugin to ensure that the node
     // types exist, so this should produce no failures...
     $this->migrateFields();
     // ...and the field instances should not have been migrated.
     $this->assertNull(FieldConfig::load('node.test_planet.field_multivalue'));
     $this->assertNull(FieldConfig::load('node.test_planet.field_test_text_single_checkbox'));
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:13,代码来源:MigrateFieldInstanceTest.php

示例8: testUserPictureFieldInstance

 /**
  * Tests the Drupal 6 user picture to Drupal 8 picture field instance migration.
  */
 public function testUserPictureFieldInstance()
 {
     $field = FieldConfig::load('user.user.user_picture');
     $settings = $field->getSettings();
     $this->assertIdentical('png gif jpg jpeg', $settings['file_extensions']);
     $this->assertIdentical('pictures', $settings['file_directory']);
     $this->assertIdentical('30KB', $settings['max_filesize']);
     $this->assertIdentical('85x85', $settings['max_resolution']);
     $this->assertIdentical(array('user', 'user', 'user_picture'), entity_load('migration', 'd6_user_picture_field_instance')->getIdMap()->lookupDestinationID(array('')));
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:13,代码来源:MigrateUserPictureInstanceTest.php

示例9: testVocabularyFieldInstance

 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyFieldInstance()
 {
     // Test that the field exists.
     $field_id = 'node.article.tags';
     $field = FieldConfig::load($field_id);
     $this->assertIdentical($field_id, $field->id(), 'Field instance exists on article bundle.');
     // Test the page bundle as well.
     $field_id = 'node.page.tags';
     $field = FieldConfig::load($field_id);
     $this->assertIdentical($field_id, $field->id(), 'Field instance exists on page bundle.');
     $this->assertIdentical(array('node', 'article', 'tags'), entity_load('migration', 'd6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article')));
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:15,代码来源:MigrateVocabularyFieldInstanceTest.php

示例10: testFieldInstances

 /**
  * Tests migrating D7 fields to field_storage_config entities, then rolling back.
  */
 public function testFieldInstances()
 {
     // Test that the field instances have migrated (prior to rollback).
     parent::testFieldInstances();
     $this->executeRollback('d7_field_instance');
     $this->executeRollback('d7_field');
     // Check that field instances have been rolled back.
     $field_instance_ids = ['comment.comment_node_page.comment_body', 'node.page.body', 'comment.comment_node_article.comment_body', 'node.article.body', 'node.article.field_tags', 'node.article.field_image', 'comment.comment_node_blog.comment_body', 'node.blog.body', 'comment.comment_node_book.comment_body', 'node.book.body', 'node.forum.taxonomy_forums', 'comment.comment_node_forum.comment_body', 'node.forum.body', 'comment.comment_node_test_content_type.comment_body', 'node.test_content_type.field_boolean', 'node.test_content_type.field_email', 'node.test_content_type.field_phone', 'node.test_content_type.field_date', 'node.test_content_type.field_date_with_end_time', 'node.test_content_type.field_file', 'node.test_content_type.field_float', 'node.test_content_type.field_images', 'node.test_content_type.field_integer', 'node.test_content_type.field_link', 'node.test_content_type.field_text_list', 'node.test_content_type.field_integer_list', 'node.test_content_type.field_long_text', 'node.test_content_type.field_term_reference', 'node.test_content_type.field_text', 'comment.comment_node_test_content_type.field_integer', 'user.user.field_file'];
     foreach ($field_instance_ids as $field_instance_id) {
         $this->assertNull(FieldConfig::load($field_instance_id));
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:15,代码来源:RollbackFieldInstanceTest.php

示例11: assertEntity

 /**
  * Asserts various aspects of a field config entity.
  *
  * @param string $id
  *   The entity ID in the form ENTITY_TYPE.BUNDLE.FIELD_NAME.
  * @param string $expected_label
  *   The expected field label.
  * @param string $expected_field_type
  *   The expected field type.
  * @param boolean $is_required
  *   Whether or not the field is required.
  */
 protected function assertEntity($id, $expected_label, $expected_field_type, $is_required)
 {
     list($expected_entity_type, $expected_bundle, $expected_name) = explode('.', $id);
     /** @var \Drupal\field\FieldConfigInterface $field */
     $field = FieldConfig::load($id);
     $this->assertTrue($field instanceof FieldConfigInterface);
     $this->assertIdentical($expected_label, $field->label());
     $this->assertIdentical($expected_field_type, $field->getType());
     $this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId());
     $this->assertIdentical($expected_bundle, $field->getTargetBundle());
     $this->assertIdentical($expected_name, $field->getName());
     $this->assertEqual($is_required, $field->isRequired());
     $this->assertIdentical($expected_entity_type . '.' . $expected_name, $field->getFieldStorageDefinition()->id());
 }
开发者ID:komejo,项目名称:article-test,代码行数:26,代码来源:MigrateFieldInstanceTest.php

示例12: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name');
     $field_storage = array('field_name' => $this->fieldName, 'entity_type' => $this->entityTypeId, 'type' => 'test_field', 'cardinality' => 4);
     entity_create('field_storage_config', $field_storage)->save();
     $this->fieldStorage = FieldStorageConfig::load($this->entityTypeId . '.' . $this->fieldName);
     $field = array('field_storage' => $this->fieldStorage, 'bundle' => $this->entityTypeId);
     entity_create('field_config', $field)->save();
     $this->field = FieldConfig::load($this->entityTypeId . '.' . $field['bundle'] . '.' . $this->fieldName);
     entity_get_form_display($this->entityTypeId, $this->entityTypeId, 'default')->setComponent($this->fieldName)->save();
     for ($i = 0; $i < 3; ++$i) {
         ConfigurableLanguage::create(array('id' => 'l' . $i, 'label' => $this->randomString()))->save();
     }
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:15,代码来源:TranslationWebTest.php

示例13: testUploadFieldInstance

 /**
  * Tests the Drupal 6 upload settings to Drupal 8 field instance migration.
  */
 public function testUploadFieldInstance()
 {
     $field = FieldConfig::load('node.page.upload');
     $settings = $field->getSettings();
     $this->assertIdentical('node.page.upload', $field->id());
     $this->assertIdentical('jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp', $settings['file_extensions']);
     $this->assertIdentical('1MB', $settings['max_filesize']);
     $this->assertIdentical(TRUE, $settings['description_field']);
     $field = FieldConfig::load('node.story.upload');
     $this->assertIdentical('node.story.upload', $field->id());
     // Shouldn't exist.
     $field = FieldConfig::load('node.article.upload');
     $this->assertTrue(is_null($field));
     $this->assertIdentical(array('node', 'page', 'upload'), Migration::load('d6_upload_field_instance')->getIdMap()->lookupDestinationID(array('page')));
 }
开发者ID:neetumorwani,项目名称:blogging,代码行数:18,代码来源:MigrateUploadInstanceTest.php

示例14: testBlockContentBodyFieldMigration

 /**
  * Tests the block content body field migration.
  */
 public function testBlockContentBodyFieldMigration()
 {
     /** @var \Drupal\field\FieldStorageConfigInterface $storage */
     $storage = FieldStorageConfig::load('block_content.body');
     $this->assertTrue($storage instanceof FieldStorageConfigInterface);
     $this->assertIdentical('block_content', $storage->getTargetEntityTypeId());
     $this->assertIdentical(['basic'], array_values($storage->getBundles()));
     $this->assertIdentical('body', $storage->getName());
     /** @var \Drupal\field\FieldConfigInterface $field */
     $field = FieldConfig::load('block_content.basic.body');
     $this->assertTrue($field instanceof FieldConfigInterface);
     $this->assertIdentical('block_content', $field->getTargetEntityTypeId());
     $this->assertIdentical('basic', $field->getTargetBundle());
     $this->assertIdentical('body', $field->getName());
     $this->assertIdentical('Body', $field->getLabel());
 }
开发者ID:318io,项目名称:318-io,代码行数:19,代码来源:MigrateBlockContentBodyFieldTest.php

示例15: testNodeDeletion

 /**
  * Tests that comments are deleted with the node.
  */
 function testNodeDeletion()
 {
     $this->drupalLogin($this->webUser);
     $comment = $this->postComment($this->node, $this->randomMachineName(), $this->randomMachineName());
     $this->assertTrue($comment->id(), 'The comment could be loaded.');
     $this->node->delete();
     $this->assertFalse(Comment::load($comment->id()), 'The comment could not be loaded after the node was deleted.');
     // Make sure the comment field storage and all its fields are deleted when
     // the node type is deleted.
     $this->assertNotNull(FieldStorageConfig::load('node.comment'), 'Comment field storage exists');
     $this->assertNotNull(FieldConfig::load('node.article.comment'), 'Comment field exists');
     // Delete the node type.
     entity_delete_multiple('node_type', array($this->node->bundle()));
     $this->assertNull(FieldStorageConfig::load('node.comment'), 'Comment field storage deleted');
     $this->assertNull(FieldConfig::load('node.article.comment'), 'Comment field deleted');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:19,代码来源:CommentNodeChangesTest.php


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