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


PHP EntityViewDisplay::load方法代码示例

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


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

示例1: dsExportablesSetup

 /**
  * Enables the exportables module.
  */
 function dsExportablesSetup()
 {
     /** @var $display EntityViewDisplay */
     $display = EntityViewDisplay::load('node.article.default');
     $display->delete();
     \Drupal::service('module_installer')->install(array('ds_exportables_test'));
 }
开发者ID:neeravbm,项目名称:unify-d8,代码行数:10,代码来源:ExportablesTest.php

示例2: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('local_tasks_block');
     $this->drupalPlaceBlock('local_actions_block');
     $this->drupalPlaceBlock('page_title_block');
     $this->type = $this->createProfileType('test', 'Test profile', TRUE);
     $id = $this->type->id();
     $field_storage = FieldStorageConfig::create(['field_name' => 'profile_fullname', 'entity_type' => 'profile', 'type' => 'text']);
     $field_storage->save();
     $this->field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->type->id(), 'label' => 'Full name']);
     $this->field->save();
     // Configure the default display.
     $this->display = EntityViewDisplay::load("profile.{$this->type->id()}.default");
     if (!$this->display) {
         $this->display = EntityViewDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]);
         $this->display->save();
     }
     $this->display->setComponent($this->field->getName(), ['type' => 'string'])->save();
     // Configure rhe default form.
     $this->form = EntityFormDisplay::load("profile.{$this->type->id()}.default");
     if (!$this->form) {
         $this->form = EntityFormDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]);
         $this->form->save();
     }
     $this->form->setComponent($this->field->getName(), ['type' => 'string_textfield'])->save();
     $this->checkPermissions(['administer profile types', "view own {$id} profile", "view any {$id} profile", "add own {$id} profile", "add any {$id} profile", "edit own {$id} profile", "edit any {$id} profile", "delete own {$id} profile", "delete any {$id} profile"]);
     user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['access user profiles']);
     $this->adminUser = $this->drupalCreateUser(['administer profile types', "view any {$id} profile", "add any {$id} profile", "edit any {$id} profile", "delete any {$id} profile"]);
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:33,代码来源:ProfileTestBase.php

示例3: testUserPictureEntityDisplay

 /**
  * Tests the Drupal 7 user picture to Drupal 8 entity display migration.
  */
 public function testUserPictureEntityDisplay()
 {
     $component = EntityViewDisplay::load('user.user.default')->getComponent('user_picture');
     $this->assertIdentical('image', $component['type']);
     $this->assertIdentical('', $component['settings']['image_style']);
     $this->assertIdentical('content', $component['settings']['image_link']);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:10,代码来源:MigrateUserPictureEntityDisplayTest.php

示例4: testEntityReferenceXSS

 /**
  * Tests markup is escaped in the entity reference select and label formatter.
  */
 public function testEntityReferenceXSS()
 {
     $this->drupalCreateContentType(['type' => 'article']);
     // Create a node with markup in the title.
     $node_type_one = $this->drupalCreateContentType();
     $node = ['type' => $node_type_one->id(), 'title' => '<em>I am kitten</em>'];
     $referenced_node = $this->drupalCreateNode($node);
     $node_type_two = $this->drupalCreateContentType(['name' => '<em>bundle with markup</em>']);
     $this->drupalCreateNode(['type' => $node_type_two->id(), 'title' => 'My bundle has markup']);
     $this->createEntityReferenceField('node', 'article', 'entity_reference_test', 'Entity Reference test', 'node', 'default', ['target_bundles' => [$node_type_one->id(), $node_type_two->id()]]);
     EntityFormDisplay::load('node.article.default')->setComponent('entity_reference_test', ['type' => 'options_select'])->save();
     EntityViewDisplay::load('node.article.default')->setComponent('entity_reference_test', ['type' => 'entity_reference_label'])->save();
     // Create a node and reference the node with markup in the title.
     $this->drupalLogin($this->rootUser);
     $this->drupalGet('node/add/article');
     $this->assertEscaped($referenced_node->getTitle());
     $this->assertEscaped($node_type_two->label());
     $edit = ['title[0][value]' => $this->randomString(), 'entity_reference_test' => $referenced_node->id()];
     $this->drupalPostForm(NULL, $edit, 'Save and publish');
     $this->assertEscaped($referenced_node->getTitle());
     // Test the options_buttons type.
     EntityFormDisplay::load('node.article.default')->setComponent('entity_reference_test', ['type' => 'options_buttons'])->save();
     $this->drupalGet('node/add/article');
     $this->assertEscaped($referenced_node->getTitle());
     // options_buttons does not support optgroups.
     $this->assertNoText('bundle with markup');
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:30,代码来源:EntityReferenceXSSTest.php

示例5: assertDisplay

 /**
  * Asserts a display entity.
  *
  * @param string $id
  *   The entity ID.
  * @param string $component_id
  *   The ID of the display component.
  */
 protected function assertDisplay($id, $component_id)
 {
     $component = EntityViewDisplay::load($id)->getComponent($component_id);
     $this->assertTrue(is_array($component));
     $this->assertIdentical('hidden', $component['label']);
     $this->assertIdentical('comment_default', $component['type']);
     $this->assertIdentical(20, $component['weight']);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:16,代码来源:MigrateCommentEntityDisplayTest.php

示例6: testCommentEntityDisplay

 /**
  * Tests comment variables migrated into an entity display.
  */
 public function testCommentEntityDisplay()
 {
     foreach (['page', 'story', 'article'] as $type) {
         $component = EntityViewDisplay::load('node.' . $type . '.default')->getComponent('comment');
         $this->assertIdentical('hidden', $component['label']);
         $this->assertIdentical('comment_default', $component['type']);
         $this->assertIdentical(20, $component['weight']);
     }
 }
开发者ID:318io,项目名称:318-io,代码行数:12,代码来源:MigrateCommentVariableEntityDisplayTest.php

示例7: testEntityDisplayDependency

 /**
  * Tests the dependency between ImageStyle and entity display components.
  */
 public function testEntityDisplayDependency()
 {
     // Create two image styles.
     /** @var \Drupal\image\ImageStyleInterface $style */
     $style = ImageStyle::create(['name' => 'main_style']);
     $style->save();
     /** @var \Drupal\image\ImageStyleInterface $replacement */
     $replacement = ImageStyle::create(['name' => 'replacement_style']);
     $replacement->save();
     // Create a node-type, named 'note'.
     $node_type = NodeType::create(['type' => 'note']);
     $node_type->save();
     // Create an image field and attach it to the 'note' node-type.
     FieldStorageConfig::create(['entity_type' => 'node', 'field_name' => 'sticker', 'type' => 'image'])->save();
     FieldConfig::create(['entity_type' => 'node', 'field_name' => 'sticker', 'bundle' => 'note'])->save();
     // Create the default entity view display and set the 'sticker' field to use
     // the 'main_style' images style in formatter.
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
     $view_display = EntityViewDisplay::create(['targetEntityType' => 'node', 'bundle' => 'note', 'mode' => 'default', 'status' => TRUE])->setComponent('sticker', ['settings' => ['image_style' => 'main_style']]);
     $view_display->save();
     // Create the default entity form display and set the 'sticker' field to use
     // the 'main_style' images style in the widget.
     /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
     $form_display = EntityFormDisplay::create(['targetEntityType' => 'node', 'bundle' => 'note', 'mode' => 'default', 'status' => TRUE])->setComponent('sticker', ['settings' => ['preview_image_style' => 'main_style']]);
     $form_display->save();
     // Check that the entity displays exists before dependency removal.
     $this->assertNotNull(EntityViewDisplay::load($view_display->id()));
     $this->assertNotNull(EntityFormDisplay::load($form_display->id()));
     // Delete the 'main_style' image style. Before that, emulate the UI process
     // of selecting a replacement style by setting the replacement image style
     // ID in the image style storage.
     /** @var \Drupal\image\ImageStyleStorageInterface $storage */
     $storage = $this->container->get('entity.manager')->getStorage($style->getEntityTypeId());
     $storage->setReplacementId('main_style', 'replacement_style');
     $style->delete();
     // Check that the entity displays exists after dependency removal.
     $this->assertNotNull($view_display = EntityViewDisplay::load($view_display->id()));
     $this->assertNotNull($form_display = EntityFormDisplay::load($form_display->id()));
     // Check that the 'sticker' formatter component exists in both displays.
     $this->assertNotNull($formatter = $view_display->getComponent('sticker'));
     $this->assertNotNull($widget = $form_display->getComponent('sticker'));
     // Check that both displays are using now 'replacement_style' for images.
     $this->assertSame('replacement_style', $formatter['settings']['image_style']);
     $this->assertSame('replacement_style', $widget['settings']['preview_image_style']);
     // Delete the 'replacement_style' without setting a replacement image style.
     $replacement->delete();
     // The entity view and form displays exists after dependency removal.
     $this->assertNotNull($view_display = EntityViewDisplay::load($view_display->id()));
     $this->assertNotNull($form_display = EntityFormDisplay::load($form_display->id()));
     // The 'sticker' formatter component should be hidden in view display.
     $this->assertNull($view_display->getComponent('sticker'));
     $this->assertTrue($view_display->get('hidden')['sticker']);
     // The 'sticker' widget component should be active in form displays, but the
     // image preview should be disabled.
     $this->assertNotNull($widget = $form_display->getComponent('sticker'));
     $this->assertSame('', $widget['settings']['preview_image_style']);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:60,代码来源:ImageStyleIntegrationTest.php

示例8: testVocabularyEntityDisplay

 /**
  * Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
  */
 public function testVocabularyEntityDisplay()
 {
     // Test that the field exists.
     $component = EntityViewDisplay::load('node.page.default')->getComponent('tags');
     $this->assertIdentical('entity_reference_label', $component['type']);
     $this->assertIdentical(20, $component['weight']);
     // Test the Id map.
     $this->assertIdentical(array('node', 'article', 'default', 'tags'), $this->getMigration('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:12,代码来源:MigrateVocabularyEntityDisplayTest.php

示例9: testUploadEntityDisplay

 /**
  * Tests the Drupal 6 upload settings to Drupal 8 entity display migration.
  */
 public function testUploadEntityDisplay()
 {
     $display = EntityViewDisplay::load('node.page.default');
     $component = $display->getComponent('upload');
     $this->assertIdentical('file_default', $component['type']);
     $display = EntityViewDisplay::load('node.story.default');
     $component = $display->getComponent('upload');
     $this->assertIdentical('file_default', $component['type']);
     // Assure this doesn't exist.
     $display = EntityViewDisplay::load('node.article.default');
     $component = $display->getComponent('upload');
     $this->assertTrue(is_null($component));
     $this->assertIdentical(array('node', 'page', 'default', 'upload'), $this->getMigration('d6_upload_entity_display')->getIdMap()->lookupDestinationID(array('page')));
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:17,代码来源:MigrateUploadEntityDisplayTest.php

示例10: testDelete

 /**
  * Tests image style deletion.
  */
 public function testDelete()
 {
     $this->drupalGet('admin/config/media/image-styles/manage/medium/delete');
     // Checks that the 'replacement' select element is displayed.
     $this->assertFieldByName('replacement');
     // Checks that UI messages are correct.
     $this->assertRaw(t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.'));
     $this->assertNoRaw(t('All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.'));
     // Delete 'medium' image style but replace it with 'thumbnail'. This style
     // is involved in 'node.page.default' display view and form.
     $this->drupalPostForm(NULL, ['replacement' => 'thumbnail'], t('Delete'));
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
     $view_display = EntityViewDisplay::load('node.page.default');
     // Checks that the formatter setting is replaced.
     if ($this->assertNotNull($component = $view_display->getComponent('foo'))) {
         $this->assertIdentical($component['settings']['image_style'], 'thumbnail');
     }
     /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display */
     $form_display = EntityFormDisplay::load('node.page.default');
     // Check that the widget setting is replaced.
     if ($this->assertNotNull($component = $form_display->getComponent('foo'))) {
         $this->assertIdentical($component['settings']['preview_image_style'], 'thumbnail');
     }
     $this->drupalGet('admin/config/media/image-styles/manage/thumbnail/delete');
     // Checks that the 'replacement' select element is displayed.
     $this->assertFieldByName('replacement');
     // Checks that UI messages are correct.
     $this->assertRaw(t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.'));
     $this->assertNoRaw(t('All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.'));
     // Delete 'thumbnail' image style. Provide no replacement.
     $this->drupalPostForm(NULL, [], t('Delete'));
     $view_display = EntityViewDisplay::load('node.page.default');
     // Checks that the formatter setting is disabled.
     $this->assertNull($view_display->getComponent('foo'));
     $this->assertNotNull($view_display->get('hidden')['foo']);
     // Checks that widget setting is preserved with the image preview disabled.
     $form_display = EntityFormDisplay::load('node.page.default');
     $this->assertNotNull($widget = $form_display->getComponent('foo'));
     $this->assertIdentical($widget['settings']['preview_image_style'], '');
     // Now, there's only one image style configured on the system: 'large'.
     $this->drupalGet('admin/config/media/image-styles/manage/large/delete');
     // Checks that the 'replacement' select element is not displayed.
     $this->assertNoFieldByName('replacement');
     // Checks that UI messages are correct.
     $this->assertNoRaw(t('If this style is in use on the site, you may select another style to replace it. All images that have been generated for this style will be permanently deleted. If no replacement style is selected, the dependent configurations might need manual reconfiguration.'));
     $this->assertRaw(t('All images that have been generated for this style will be permanently deleted. The dependent configurations might need manual reconfiguration.'));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:50,代码来源:ImageStyleDeleteTest.php

示例11: testUserProfileFields

 /**
  * Tests migration of user profile fields.
  */
 public function testUserProfileFields()
 {
     $display = EntityViewDisplay::load('user.user.default');
     // Test a text field.
     $component = $display->getComponent('profile_color');
     $this->assertIdentical('text_default', $component['type']);
     // Test a list field.
     $component = $display->getComponent('profile_bands');
     $this->assertIdentical('text_default', $component['type']);
     // Test a date field.
     $component = $display->getComponent('profile_birthdate');
     $this->assertIdentical('datetime_default', $component['type']);
     // Test PROFILE_PRIVATE field is hidden.
     $this->assertNull($display->getComponent('profile_sell_address'));
     // Test PROFILE_HIDDEN field is hidden.
     $this->assertNull($display->getComponent('profile_sold_to'));
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:20,代码来源:MigrateUserProfileEntityDisplayTest.php

示例12: testPostUpdateDependency

 /**
  * Tests post-update responsive_image_post_update_dependency().
  *
  * @see responsive_image_post_update_dependency()
  */
 public function testPostUpdateDependency()
 {
     // Installing the 'wide' responsive image style.
     $wide_image_style = Yaml::decode(file_get_contents(__DIR__ . '/../../../../../profiles/standard/config/optional/responsive_image.styles.wide.yml'));
     $this->config('responsive_image.styles.wide')->setData($wide_image_style)->save(TRUE);
     // Change 'field_image' formatter to a responsive image formatter.
     $options = ['type' => 'responsive_image', 'label' => 'hidden', 'settings' => ['responsive_image_style' => 'wide', 'image_link' => ''], 'third_party_settings' => []];
     $display = $this->config('core.entity_view_display.node.article.default');
     $display->set('content.field_image', $options)->save(TRUE);
     // Check that there's no dependency to 'responsive_image.styles.wide'.
     $dependencies = $display->get('dependencies.config') ?: [];
     $this->assertFalse(in_array('responsive_image.styles.wide', $dependencies));
     // Run updates.
     $this->runUpdates();
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
     $view_display = EntityViewDisplay::load('node.article.default');
     $dependencies = $view_display->getDependencies() + ['config' => []];
     // Check that post-update added a 'responsive_image.styles.wide' dependency.
     $this->assertTrue(in_array('responsive_image.styles.wide', $dependencies['config']));
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:25,代码来源:ResponsiveImageUpdateTest.php

示例13: testViewMode

 /**
  * Tests view mode setting integration.
  *
  * @see comment_entity_view_display_presave()
  * @see CommentDefaultFormatter::calculateDependencies()
  */
 public function testViewMode()
 {
     $mode = Unicode::strtolower($this->randomMachineName());
     // Create a new comment view mode and a view display entity.
     EntityViewMode::create(['id' => "comment.{$mode}", 'targetEntityType' => 'comment', 'settings' => ['comment_type' => 'comment']])->save();
     EntityViewDisplay::create(['targetEntityType' => 'comment', 'bundle' => 'comment', 'mode' => $mode])->setStatus(TRUE)->save();
     // Create a comment field attached to a host 'entity_test' entity.
     FieldStorageConfig::create(['entity_type' => 'entity_test', 'type' => 'comment', 'field_name' => $field_name = Unicode::strtolower($this->randomMachineName()), 'settings' => ['comment_type' => 'comment']])->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'bundle' => 'entity_test', 'field_name' => $field_name])->save();
     $component = ['type' => 'comment_default', 'settings' => ['view_mode' => $mode, 'pager_id' => 0]];
     // Create a new 'entity_test' view display on host entity that uses the
     // custom comment display in field formatter to show the field.
     EntityViewDisplay::create(['targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'default'])->setComponent($field_name, $component)->setStatus(TRUE)->save();
     $host_display_id = 'entity_test.entity_test.default';
     $comment_display_id = "comment.comment.{$mode}";
     // Disable the "comment.comment.$mode" display.
     EntityViewDisplay::load($comment_display_id)->setStatus(FALSE)->save();
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $host_display */
     $host_display = EntityViewDisplay::load($host_display_id);
     // Check that the field formatter has been disabled on host view display.
     $this->assertNull($host_display->getComponent($field_name));
     $this->assertTrue($host_display->get('hidden')[$field_name]);
     // Check that the proper warning has been logged.
     $arguments = ['@id' => $host_display_id, '@name' => $field_name, '@display' => EntityViewMode::load("comment.{$mode}")->label(), '@mode' => $mode];
     $logged = (bool) Database::getConnection()->select('watchdog')->fields('watchdog', ['wid'])->condition('type', 'system')->condition('message', "View display '@id': Comment field formatter '@name' was disabled because it is using the comment view display '@display' (@mode) that was just disabled.")->condition('variables', serialize($arguments))->execute()->fetchField();
     $this->assertTrue($logged);
     // Re-enable the comment view display.
     EntityViewDisplay::load($comment_display_id)->setStatus(TRUE)->save();
     // Re-enable the comment field formatter on host entity view display.
     EntityViewDisplay::load($host_display_id)->setComponent($field_name, $component)->save();
     // Delete the "comment.$mode" view mode.
     EntityViewMode::load("comment.{$mode}")->delete();
     // Check that the comment view display entity has been deleted too.
     $this->assertNull(EntityViewDisplay::load($comment_display_id));
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
     $host_display = EntityViewDisplay::load($host_display_id);
     // Check that the field formatter has been disabled on host view display.
     $this->assertNull($host_display->getComponent($field_name));
     $this->assertTrue($host_display->get('hidden')[$field_name]);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:46,代码来源:CommentIntegrationTest.php

示例14: testEntityViewDisplayDependency

 /**
  * Tests integration with entity view display.
  */
 public function testEntityViewDisplayDependency()
 {
     // Create a responsive image style.
     ResponsiveImageStyle::create(['id' => 'foo', 'label' => 'Foo', 'breakpoint_group' => 'responsive_image_test_module'])->save();
     // Create an image field to be used with a responsive image formatter.
     FieldStorageConfig::create(['type' => 'image', 'entity_type' => 'entity_test', 'field_name' => 'bar'])->save();
     FieldConfig::create(['entity_type' => 'entity_test', 'bundle' => 'entity_test', 'field_name' => 'bar'])->save();
     /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
     $display = EntityViewDisplay::create(['targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'default']);
     $display->setComponent('bar', ['type' => 'responsive_image', 'label' => 'hidden', 'settings' => ['responsive_image_style' => 'foo', 'image_link' => ''], 'third_party_settings' => []])->save();
     // Check that the 'foo' field is on the display.
     $this->assertNotNull($display = EntityViewDisplay::load('entity_test.entity_test.default'));
     $this->assertTrue($display->getComponent('bar'));
     $this->assertArrayNotHasKey('bar', $display->get('hidden'));
     // Delete the responsive image style.
     ResponsiveImageStyle::load('foo')->delete();
     // Check that the view display was not deleted.
     $this->assertNotNull($display = EntityViewDisplay::load('entity_test.entity_test.default'));
     // Check that the 'foo' field was disabled.
     $this->assertNull($display->getComponent('bar'));
     $this->assertArrayHasKey('bar', $display->get('hidden'));
 }
开发者ID:sgtsaughter,项目名称:d8portfolio,代码行数:25,代码来源:ResponsiveImageIntegrationTest.php

示例15: testFormatterUI

 /**
  * Tests formatter settings.
  */
 function testFormatterUI()
 {
     $manage_fields = 'admin/structure/types/manage/' . $this->type;
     $manage_display = $manage_fields . '/display';
     // Create a field, and a node with some data for the field.
     $this->fieldUIAddNewField($manage_fields, 'test', 'Test field');
     // Get the display options (formatter and settings) that were automatically
     // assigned for the 'default' display.
     $display = entity_get_display('node', $this->type, 'default');
     $display_options = $display->getComponent('field_test');
     $format = $display_options['type'];
     $default_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($format);
     $setting_name = key($default_settings);
     $setting_value = $display_options['settings'][$setting_name];
     // Display the "Manage display" screen and check that the expected formatter
     // is selected.
     $this->drupalGet($manage_display);
     $this->assertFieldByName('fields[field_test][type]', $format, 'The expected formatter is selected.');
     $this->assertText("{$setting_name}: {$setting_value}", 'The expected summary is displayed.');
     // Check whether formatter weights are respected.
     $result = $this->xpath('//select[@id=:id]/option', array(':id' => 'edit-fields-field-test-type'));
     $options = array_map(function ($item) {
         return (string) $item->attributes()->value[0];
     }, $result);
     $expected_options = array('field_no_settings', 'field_empty_test', 'field_empty_setting', 'field_test_default', 'field_test_multiple', 'field_test_with_prepare_view', 'field_test_applicable', 'hidden');
     $this->assertEqual($options, $expected_options, 'The expected formatter ordering is respected.');
     // Change the formatter and check that the summary is updated.
     $edit = array('fields[field_test][type]' => 'field_test_multiple', 'refresh_rows' => 'field_test');
     $this->drupalPostAjaxForm(NULL, $edit, array('op' => t('Refresh')));
     $format = 'field_test_multiple';
     $default_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($format);
     $setting_name = key($default_settings);
     $setting_value = $default_settings[$setting_name];
     $this->assertFieldByName('fields[field_test][type]', $format, 'The expected formatter is selected.');
     $this->assertText("{$setting_name}: {$setting_value}", 'The expected summary is displayed.');
     // Submit the form and check that the display is updated.
     $this->drupalPostForm(NULL, array(), t('Save'));
     $display = entity_get_display('node', $this->type, 'default');
     $display_options = $display->getComponent('field_test');
     $current_format = $display_options['type'];
     $current_setting_value = $display_options['settings'][$setting_name];
     $this->assertEqual($current_format, $format, 'The formatter was updated.');
     $this->assertEqual($current_setting_value, $setting_value, 'The setting was updated.');
     // Assert that hook_field_formatter_settings_summary_alter() is called.
     $this->assertText('field_test_field_formatter_settings_summary_alter');
     // Click on the formatter settings button to open the formatter settings
     // form.
     $this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
     // Assert that the field added in
     // field_test_field_formatter_third_party_settings_form() is present.
     $fieldname = 'fields[field_test][settings_edit_form][third_party_settings][field_third_party_test][field_test_field_formatter_third_party_settings_form]';
     $this->assertField($fieldname, 'The field added in hook_field_formatter_third_party_settings_form() is present on the settings form.');
     $edit = array($fieldname => 'foo');
     $this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update");
     // Save the form to save the third party settings.
     $this->drupalPostForm(NULL, array(), t('Save'));
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     $id = 'node.' . $this->type . '.default';
     $storage = $this->container->get('entity_type.manager')->getStorage('entity_view_display');
     $storage->resetCache([$id]);
     $display = $storage->load($id);
     $this->assertEqual($display->getRenderer('field_test')->getThirdPartySetting('field_third_party_test', 'field_test_field_formatter_third_party_settings_form'), 'foo');
     $this->assertTrue(in_array('field_third_party_test', $display->calculateDependencies()->getDependencies()['module']), 'The display has a dependency on field_third_party_test module.');
     // Confirm that the third party settings are not updated on the settings form.
     $this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
     $this->assertFieldByName($fieldname, '');
     // Test the empty setting formatter.
     $edit = array('fields[field_test][type]' => 'field_empty_setting');
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertNoText('Default empty setting now has a value.');
     $this->assertFieldById('edit-fields-field-test-settings-edit');
     $this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
     $fieldname = 'fields[field_test][settings_edit_form][settings][field_empty_setting]';
     $edit = array($fieldname => 'non empty setting');
     $this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update");
     $this->assertText('Default empty setting now has a value.');
     // Test the settings form behavior. An edit button should be present since
     // there are third party settings to configure.
     $edit = array('fields[field_test][type]' => 'field_no_settings', 'refresh_rows' => 'field_test');
     $this->drupalPostAjaxForm(NULL, $edit, array('op' => t('Refresh')));
     $this->assertFieldByName('field_test_settings_edit');
     // Make sure we can save the third party settings when there are no settings available
     $this->drupalPostAjaxForm(NULL, array(), "field_test_settings_edit");
     $this->drupalPostAjaxForm(NULL, $edit, "field_test_plugin_settings_update");
     // When a module providing third-party settings to a formatter (or widget)
     // is uninstalled, the formatter remains enabled but the provided settings,
     // together with the corresponding form elements, are removed from the
     // display component.
     \Drupal::service('module_installer')->uninstall(array('field_third_party_test'));
     // Ensure the button is still there after the module has been disabled.
     $this->drupalGet($manage_display);
     $this->assertResponse(200);
     $this->assertFieldByName('field_test_settings_edit');
     // Ensure that third-party form elements are not present anymore.
     $this->drupalPostAjaxForm(NULL, array(), 'field_test_settings_edit');
     $fieldname = 'fields[field_test][settings_edit_form][third_party_settings][field_third_party_test][field_test_field_formatter_third_party_settings_form]';
     $this->assertNoField($fieldname);
//.........这里部分代码省略.........
开发者ID:eigentor,项目名称:tommiblog,代码行数:101,代码来源:ManageDisplayTest.php


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