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


PHP FieldStorageConfig::load方法代码示例

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


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

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

示例2: testUserProfileFields

 /**
  * Tests migration of user profile fields.
  */
 public function testUserProfileFields()
 {
     // Migrated a text field.
     $field_storage = FieldStorageConfig::load('user.profile_color');
     $this->assertIdentical('text', $field_storage->getType(), 'Field type is text.');
     $this->assertIdentical(1, $field_storage->getCardinality(), 'Text field has correct cardinality');
     // Migrated a textarea.
     $field_storage = FieldStorageConfig::load('user.profile_biography');
     $this->assertIdentical('text_long', $field_storage->getType(), 'Field type is text_long.');
     // Migrated checkbox field.
     $field_storage = FieldStorageConfig::load('user.profile_sell_address');
     $this->assertIdentical('boolean', $field_storage->getType(), 'Field type is boolean.');
     // Migrated selection field.
     $field_storage = FieldStorageConfig::load('user.profile_sold_to');
     $this->assertIdentical('list_string', $field_storage->getType(), 'Field type is list_string.');
     $settings = $field_storage->getSettings();
     $this->assertEqual($settings['allowed_values'], array('Pill spammers' => 'Pill spammers', 'Fitness spammers' => 'Fitness spammers', 'Back\\slash' => 'Back\\slash', 'Forward/slash' => 'Forward/slash', 'Dot.in.the.middle' => 'Dot.in.the.middle', 'Faithful servant' => 'Faithful servant', 'Anonymous donor' => 'Anonymous donor'));
     $this->assertIdentical('list_string', $field_storage->getType(), 'Field type is list_string.');
     // Migrated list field.
     $field_storage = FieldStorageConfig::load('user.profile_bands');
     $this->assertIdentical('text', $field_storage->getType(), 'Field type is text.');
     $this->assertIdentical(-1, $field_storage->getCardinality(), 'List field has correct cardinality');
     /*
         // Migrated URL field.
         $field_storage = FieldStorageConfig::load('user.profile_blog');
         $this->assertIdentical('link', $field_storage->getType(), 'Field type is link.');
     */
     // Migrated date field.
     $field_storage = FieldStorageConfig::load('user.profile_birthdate');
     $this->assertIdentical('datetime', $field_storage->getType(), 'Field type is datetime.');
     $this->assertIdentical('date', $field_storage->getSettings()['datetime_type']);
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:35,代码来源:MigrateUserProfileFieldTest.php

示例3: testUserPictureField

 /**
  * Test the user picture field migration.
  */
 public function testUserPictureField()
 {
     /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
     $field_storage = FieldStorageConfig::load('user.user_picture');
     $this->assertTrue($field_storage instanceof FieldStorageConfigInterface);
     $this->assertIdentical('user.user_picture', $field_storage->id());
     $this->assertIdentical('image', $field_storage->getType());
     $this->assertIdentical('user', $field_storage->getTargetEntityTypeId());
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:12,代码来源:MigrateUserPictureFieldTest.php

示例4: testFields

 /**
  * Tests the Drupal 6 field to Drupal 8 migration.
  */
 public function testFields()
 {
     // Text field.
     /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
     $field_storage = FieldStorageConfig::load('node.field_test');
     $expected = array('max_length' => 255);
     $this->assertIdentical("text", $field_storage->getType(), t('Field type is @fieldtype. It should be text.', array('@fieldtype' => $field_storage->getType())));
     $this->assertIdentical($expected, $field_storage->getSettings(), "Field type text settings are correct");
     // Integer field.
     $field_storage = FieldStorageConfig::load('node.field_test_two');
     $this->assertIdentical("integer", $field_storage->getType(), t('Field type is @fieldtype. It should be integer.', array('@fieldtype' => $field_storage->getType())));
     // Float field.
     $field_storage = FieldStorageConfig::load('node.field_test_three');
     $this->assertIdentical("decimal", $field_storage->getType(), t('Field type is @fieldtype. It should be decimal.', array('@fieldtype' => $field_storage->getType())));
     // Link field.
     $field_storage = FieldStorageConfig::load('node.field_test_link');
     $this->assertIdentical("link", $field_storage->getType(), t('Field type is @fieldtype. It should be link.', array('@fieldtype' => $field_storage->getType())));
     // File field.
     $field_storage = FieldStorageConfig::load('node.field_test_filefield');
     $this->assertIdentical("file", $field_storage->getType(), t('Field type is @fieldtype. It should be file.', array('@fieldtype' => $field_storage->getType())));
     $field_storage = FieldStorageConfig::load('node.field_test_imagefield');
     $this->assertIdentical("image", $field_storage->getType(), t('Field type is @fieldtype. It should be image.', array('@fieldtype' => $field_storage->getType())));
     $settings = $field_storage->getSettings();
     $this->assertIdentical('file', $settings['target_type']);
     $this->assertIdentical('public', $settings['uri_scheme']);
     $this->assertIdentical(array(), array_filter($settings['default_image']));
     // Phone field.
     $field_storage = FieldStorageConfig::load('node.field_test_phone');
     $this->assertIdentical("telephone", $field_storage->getType(), t('Field type is @fieldtype. It should be telephone.', array('@fieldtype' => $field_storage->getType())));
     // Date field.
     $field_storage = FieldStorageConfig::load('node.field_test_datetime');
     $this->assertIdentical("datetime", $field_storage->getType(), t('Field type is @fieldtype. It should be datetime.', array('@fieldtype' => $field_storage->getType())));
     // Decimal field with radio buttons.
     $field_storage = FieldStorageConfig::load('node.field_test_decimal_radio_buttons');
     $this->assertIdentical("list_float", $field_storage->getType(), t('Field type is @fieldtype. It should be list_float.', array('@fieldtype' => $field_storage->getType())));
     $this->assertNotNull($field_storage->getSetting('allowed_values')['1.2'], t('First allowed value key is set to 1.2'));
     $this->assertNotNull($field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value key is set to 2.1'));
     $this->assertIdentical('1.2', $field_storage->getSetting('allowed_values')['1.2'], t('First allowed value is set to 1.2'));
     $this->assertIdentical('2.1', $field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value is set to 1.2'));
     // Float field with a single checkbox.
     $field_storage = FieldStorageConfig::load('node.field_test_float_single_checkbox');
     $this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType())));
     // Integer field with a select list.
     $field_storage = FieldStorageConfig::load('node.field_test_integer_selectlist');
     $this->assertIdentical("list_integer", $field_storage->getType(), t('Field type is @fieldtype. It should be list_integer.', array('@fieldtype' => $field_storage->getType())));
     $this->assertNotNull($field_storage->getSetting('allowed_values')['1234'], t('First allowed value key is set to 1234'));
     $this->assertNotNull($field_storage->getSetting('allowed_values')['2341'], t('Second allowed value key is set to 2341'));
     $this->assertNotNull($field_storage->getSetting('allowed_values')['3412'], t('Third allowed value key is set to 3412'));
     $this->assertNotNull($field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value key is set to 4123'));
     $this->assertIdentical('1234', $field_storage->getSetting('allowed_values')['1234'], t('First allowed value is set to 1234'));
     $this->assertIdentical('2341', $field_storage->getSetting('allowed_values')['2341'], t('Second allowed value is set to 2341'));
     $this->assertIdentical('3412', $field_storage->getSetting('allowed_values')['3412'], t('Third allowed value is set to 3412'));
     $this->assertIdentical('4123', $field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value is set to 4123'));
     // Text field with a single checkbox.
     $field_storage = FieldStorageConfig::load('node.field_test_text_single_checkbox');
     $this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType())));
 }
开发者ID:komejo,项目名称:article-test,代码行数:60,代码来源:MigrateFieldTest.php

示例5: assertEntity

 /**
  * Asserts a comment field entity.
  *
  * @param string $id
  *   The entity ID.
  * @param string $comment_type
  *   The comment type (bundle ID) the field references.
  */
 protected function assertEntity($id, $comment_type)
 {
     $entity = FieldStorageConfig::load($id);
     $this->assertTrue($entity instanceof FieldStorageConfigInterface);
     /** @var \Drupal\field\FieldStorageConfigInterface $entity */
     $this->assertIdentical('node', $entity->getTargetEntityTypeId());
     $this->assertIdentical('comment', $entity->getType());
     $this->assertIdentical($comment_type, $entity->getSetting('comment_type'));
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:17,代码来源:MigrateCommentFieldTest.php

示例6: testVocabularyField

 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyField()
 {
     // Test that the field exists.
     $field_storage_id = 'node.tags';
     $field_storage = FieldStorageConfig::load($field_storage_id);
     $this->assertIdentical($field_storage_id, $field_storage->id());
     $settings = $field_storage->getSettings();
     $this->assertIdentical('taxonomy_term', $settings['target_type'], "Target type is correct.");
     $this->assertIdentical(array('node', 'tags'), Migration::load('d6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap");
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:13,代码来源:MigrateVocabularyFieldTest.php

示例7: testVocabularyField

 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyField()
 {
     // Test that the field exists.
     $field_storage_id = 'node.tags';
     $field_storage = FieldStorageConfig::load($field_storage_id);
     $this->assertIdentical($field_storage_id, $field_storage->id());
     $settings = $field_storage->getSettings();
     $this->assertIdentical($settings['allowed_values'][0]['vocabulary'], 'tags', "Vocabulary has correct settings.");
     $this->assertIdentical(array('node', 'tags'), entity_load('migration', 'd6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap");
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:13,代码来源:MigrateVocabularyFieldTest.php

示例8: testVocabularyField

 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyField()
 {
     // Test that the field exists.
     $field_storage_id = 'node.tags';
     /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
     $field_storage = FieldStorageConfig::load($field_storage_id);
     $this->assertIdentical($field_storage_id, $field_storage->id());
     $settings = $field_storage->getSettings();
     $this->assertIdentical('taxonomy_term', $settings['target_type'], "Target type is correct.");
     $this->assertIdentical(1, $field_storage->getCardinality(), "Field cardinality in 1.");
     $this->assertIdentical(array('node', 'tags'), $this->getMigration('d6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap");
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:15,代码来源:MigrateVocabularyFieldTest.php

示例9: setUp

 /**
  * {@inheritdoc}
  *
  * Create nodes with relative dates of yesterday, today, and tomorrow.
  */
 public function setUp()
 {
     parent::setUp();
     // Set to 'today'.
     static::$date = REQUEST_TIME;
     // Change field storage to date-only.
     $storage = FieldStorageConfig::load('node.' . static::$field_name);
     $storage->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATE);
     $storage->save();
     $dates = [\Drupal::service('date.formatter')->format(static::$date + 86400, 'custom', DATETIME_DATE_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE), \Drupal::service('date.formatter')->format(static::$date, 'custom', DATETIME_DATE_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE), \Drupal::service('date.formatter')->format(static::$date - 86400, 'custom', DATETIME_DATE_STORAGE_FORMAT, DATETIME_STORAGE_TIMEZONE)];
     foreach ($dates as $date) {
         $this->nodes[] = $this->drupalCreateNode(['field_date' => ['value' => $date]]);
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:19,代码来源:FilterDateTest.php

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

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

示例12: testFields

 /**
  * Tests migrating D7 fields to field_storage_config entities, then rolling back.
  */
 public function testFields()
 {
     // Test that the fields have migrated (prior to rollback).
     parent::testFields();
     $this->executeRollback('d7_field');
     // Check that fields have been rolled back.
     $rolled_back_field_ids = ['comment.field_integer', 'node.taxonomy_forums', 'node.field_integer', 'node.field_tags', 'node.field_term_reference', 'node.field_text_list', 'node.field_text', 'node.field_phone', 'node.field_file', 'node.field_images', 'node.field_image', 'node.field_long_text', 'node.field_date_with_end_time', 'node.field_integer_list', 'node.field_date', 'node.field_link', 'node.field_float', 'node.field_boolean', 'node.field_email', 'user.field_file'];
     foreach ($rolled_back_field_ids as $field_id) {
         $this->assertNull(FieldStorageConfig::load($field_id));
     }
     // Check that fields that should persist have not been rolled back.
     $non_rolled_back_field_ids = ['node.body', 'comment.comment_body'];
     foreach ($non_rolled_back_field_ids as $field_id) {
         $this->assertNotNull(FieldStorageConfig::load($field_id));
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:19,代码来源:RollbackFieldTest.php

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

示例14: assertEntity

 /**
  * Asserts various aspects of a field_storage_config entity.
  *
  * @param string $id
  *   The entity ID in the form ENTITY_TYPE.FIELD_NAME.
  * @param string $expected_type
  *   The expected field type.
  * @param boolean $expected_translatable
  *   Whether or not the field is expected to be translatable.
  * @param integer $expected_cardinality
  *   The expected cardinality of the field.
  */
 protected function assertEntity($id, $expected_type, $expected_translatable, $expected_cardinality)
 {
     list($expected_entity_type, $expected_name) = explode('.', $id);
     /** @var \Drupal\field\FieldStorageConfigInterface $field */
     $field = FieldStorageConfig::load($id);
     $this->assertTrue($field instanceof FieldStorageConfigInterface);
     $this->assertIdentical($expected_name, $field->getName());
     $this->assertIdentical($expected_type, $field->getType());
     // FieldStorageConfig::$translatable is TRUE by default, so it is useful
     // to test for FALSE here.
     $this->assertEqual($expected_translatable, $field->isTranslatable());
     $this->assertIdentical($expected_entity_type, $field->getTargetEntityTypeId());
     if ($expected_cardinality === 1) {
         $this->assertFalse($field->isMultiple());
     } else {
         $this->assertTrue($field->isMultiple());
     }
     $this->assertIdentical($expected_cardinality, $field->getCardinality());
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:31,代码来源:MigrateFieldTest.php

示例15: testCommentFunctionality


//.........这里部分代码省略.........
     $this->assertRaw('comments[' . $comment1->id() . ']', 'Comment was published.');
     // Delete the comment.
     $this->performCommentOperation($comment1, 'delete');
     $this->drupalGet('admin/content/comment');
     $this->assertNoRaw('comments[' . $comment1->id() . ']', 'Comment was deleted.');
     // Post another comment.
     $comment1 = $this->postComment($this->entity, $this->randomMachineName(), $this->randomMachineName());
     $this->assertTrue($this->commentExists($comment1), 'Comment on test entity exists.');
     // Check that the comment was found.
     $this->drupalGet('admin/content/comment');
     $this->assertRaw('comments[' . $comment1->id() . ']', 'Comment was published.');
     // Check that entity access applies to administrative page.
     $this->assertText($this->entity->label(), 'Name of commented account found.');
     $limited_user = $this->drupalCreateUser(array('administer comments'));
     $this->drupalLogin($limited_user);
     $this->drupalGet('admin/content/comment');
     $this->assertNoText($this->entity->label(), 'No commented account name found.');
     $this->drupalLogout();
     // Deny anonymous users access to comments.
     user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array('access comments' => FALSE, 'post comments' => FALSE, 'skip comment approval' => FALSE, 'view test entity' => TRUE));
     // Attempt to view comments while disallowed.
     $this->drupalGet('entity-test/' . $this->entity->id());
     $this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.');
     $this->assertNoLink('Add new comment', 'Link to add comment was found.');
     // Attempt to view test entity comment form while disallowed.
     $this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment');
     $this->assertResponse(403);
     $this->assertNoFieldByName('subject[0][value]', '', 'Subject field not found.');
     $this->assertNoFieldByName('comment_body[0][value]', '', 'Comment field not found.');
     user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array('access comments' => TRUE, 'post comments' => FALSE, 'view test entity' => TRUE, 'skip comment approval' => FALSE));
     $this->drupalGet('entity_test/' . $this->entity->id());
     $this->assertPattern('@<h2[^>]*>Comments</h2>@', 'Comments were displayed.');
     $this->assertLink('Log in', 0, 'Link to log in was found.');
     $this->assertLink('register', 0, 'Link to register was found.');
     $this->assertNoFieldByName('subject[0][value]', '', 'Subject field not found.');
     $this->assertNoFieldByName('comment_body[0][value]', '', 'Comment field not found.');
     // Test the combination of anonymous users being able to post, but not view
     // comments, to ensure that access to post comments doesn't grant access to
     // view them.
     user_role_change_permissions(RoleInterface::ANONYMOUS_ID, array('access comments' => FALSE, 'post comments' => TRUE, 'skip comment approval' => TRUE, 'view test entity' => TRUE));
     $this->drupalGet('entity_test/' . $this->entity->id());
     $this->assertNoPattern('@<h2[^>]*>Comments</h2>@', 'Comments were not displayed.');
     $this->assertFieldByName('subject[0][value]', '', 'Subject field found.');
     $this->assertFieldByName('comment_body[0][value]', '', 'Comment field found.');
     $this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment/' . $comment1->id());
     $this->assertResponse(403);
     $this->assertNoText($comment1->getSubject(), 'Comment not displayed.');
     // Test comment field widget changes.
     $limited_user = $this->drupalCreateUser(array('administer entity_test fields', 'view test entity', 'administer entity_test content'));
     $this->drupalLogin($limited_user);
     $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment');
     $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-0');
     $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-1');
     $this->assertFieldChecked('edit-default-value-input-comment-0-status-2');
     // Test comment option change in field settings.
     $edit = array('default_value_input[comment][0][status]' => CommentItemInterface::CLOSED, 'settings[anonymous]' => COMMENT_ANONYMOUS_MAY_CONTACT);
     $this->drupalPostForm(NULL, $edit, t('Save settings'));
     $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment');
     $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-0');
     $this->assertFieldChecked('edit-default-value-input-comment-0-status-1');
     $this->assertNoFieldChecked('edit-default-value-input-comment-0-status-2');
     $this->assertFieldByName('settings[anonymous]', COMMENT_ANONYMOUS_MAY_CONTACT);
     // Add a new comment-type.
     $bundle = CommentType::create(array('id' => 'foobar', 'label' => 'Foobar', 'description' => '', 'target_entity_type_id' => 'entity_test'));
     $bundle->save();
     // Add a new comment field.
     $storage_edit = array('settings[comment_type]' => 'foobar');
     $this->fieldUIAddNewField('entity_test/structure/entity_test', 'foobar', 'Foobar', 'comment', $storage_edit);
     // Add a third comment field.
     $this->fieldUIAddNewField('entity_test/structure/entity_test', 'barfoo', 'BarFoo', 'comment', $storage_edit);
     // Check the field contains the correct comment type.
     $field_storage = FieldStorageConfig::load('entity_test.field_barfoo');
     $this->assertTrue($field_storage);
     $this->assertEqual($field_storage->getSetting('comment_type'), 'foobar');
     $this->assertEqual($field_storage->getCardinality(), 1);
     // Test the new entity commenting inherits default.
     $random_label = $this->randomMachineName();
     $data = array('bundle' => 'entity_test', 'name' => $random_label);
     $new_entity = entity_create('entity_test', $data);
     $new_entity->save();
     $this->drupalGet('entity_test/manage/' . $new_entity->id());
     $this->assertNoFieldChecked('edit-field-foobar-0-status-1');
     $this->assertFieldChecked('edit-field-foobar-0-status-2');
     $this->assertNoField('edit-field-foobar-0-status-0');
     // @todo Check proper url and form https://www.drupal.org/node/2458323
     $this->drupalGet('comment/reply/entity_test/comment/' . $new_entity->id());
     $this->assertNoFieldByName('subject[0][value]', '', 'Subject field found.');
     $this->assertNoFieldByName('comment_body[0][value]', '', 'Comment field found.');
     // Test removal of comment_body field.
     $limited_user = $this->drupalCreateUser(array('administer entity_test fields', 'post comments', 'administer comment fields', 'administer comment types'));
     $this->drupalLogin($limited_user);
     $this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment');
     $this->assertFieldByName('comment_body[0][value]', '', 'Comment body field found.');
     $this->fieldUIDeleteField('admin/structure/comment/manage/comment', 'comment.comment.comment_body', 'Comment', 'Comment settings');
     $this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment');
     $this->assertNoFieldByName('comment_body[0][value]', '', 'Comment body field not found.');
     // Set subject field to autogenerate it.
     $edit = ['subject[0][value]' => ''];
     $this->drupalPostForm(NULL, $edit, t('Save'));
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:101,代码来源:CommentNonNodeTest.php


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