當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Entity\EntityViewDisplay類代碼示例

本文整理匯總了PHP中Drupal\Core\Entity\Entity\EntityViewDisplay的典型用法代碼示例。如果您正苦於以下問題:PHP EntityViewDisplay類的具體用法?PHP EntityViewDisplay怎麽用?PHP EntityViewDisplay使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了EntityViewDisplay類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

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

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

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

示例4: generateFieldMetadata

 /**
  * {@inheritdoc}
  */
 public function generateFieldMetadata(FieldItemListInterface $items, $view_mode)
 {
     $entity = $items->getEntity();
     $field_name = $items->getFieldDefinition()->getName();
     // Early-return if user does not have access.
     $access = $this->accessChecker->accessEditEntityField($entity, $field_name);
     if (!$access) {
         return array('access' => FALSE);
     }
     // Early-return if no editor is available.
     $formatter_id = EntityViewDisplay::collectRenderDisplay($entity, $view_mode)->getRenderer($field_name)->getPluginId();
     $editor_id = $this->editorSelector->getEditor($formatter_id, $items);
     if (!isset($editor_id)) {
         return array('access' => FALSE);
     }
     // Gather metadata, allow the editor to add additional metadata of its own.
     $label = $items->getFieldDefinition()->getLabel();
     $editor = $this->editorManager->createInstance($editor_id);
     $metadata = array('label' => String::checkPlain($label), 'access' => TRUE, 'editor' => $editor_id, 'aria' => t('Entity @type @id, field @field', array('@type' => $entity->getEntityTypeId(), '@id' => $entity->id(), '@field' => $label)));
     $custom_metadata = $editor->getMetadata($items);
     if (count($custom_metadata)) {
         $metadata['custom'] = $custom_metadata;
     }
     return $metadata;
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:28,代碼來源:MetadataGenerator.php

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

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

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

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

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

示例10: image_post_update_image_style_dependencies

/**
 * Saves the image style dependencies into form and view display entities.
 */
function image_post_update_image_style_dependencies()
{
    // Merge view and form displays. Use array_values() to avoid key collisions.
    $displays = array_merge(array_values(EntityViewDisplay::loadMultiple()), array_values(EntityFormDisplay::loadMultiple()));
    /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface[] $displays */
    foreach ($displays as $display) {
        // Re-save each config entity to add missed dependencies.
        $display->save();
    }
}
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:13,代碼來源:image.post_update.php

示例11: responsive_image_post_update_recreate_dependencies

/**
 * Make responsive image formatters dependent on responsive image styles.
 */
function responsive_image_post_update_recreate_dependencies()
{
    $displays = EntityViewDisplay::loadMultiple();
    array_walk($displays, function (EntityViewDisplayInterface $entity_view_display) {
        $old_dependencies = $entity_view_display->getDependencies();
        $new_dependencies = $entity_view_display->calculateDependencies()->getDependencies();
        if ($old_dependencies !== $new_dependencies) {
            $entity_view_display->save();
        }
    });
}
開發者ID:eigentor,項目名稱:tommiblog,代碼行數:14,代碼來源:responsive_image.post_update.php

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

示例13: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema($this->entityTypeId);
     EntityViewDisplay::create(['targetEntityType' => 'entity_test', 'bundle' => 'entity_test', 'mode' => 'default'])->save();
     FieldStorageConfig::create(['field_name' => $this->fieldName, 'entity_type' => $this->entityTypeId, 'type' => 'video_embed_field'])->save();
     FieldConfig::create(['entity_type' => $this->entityTypeId, 'field_name' => $this->fieldName, 'bundle' => $this->entityTypeId])->save();
     // Fake colorbox being enabled for the purposes of testing.
     $this->container->get('module_handler')->addModule('colorbox', NULL);
     // Use a HTTP mock which won't attempt to download anything.
     $this->container->set('http_client', new MockHttpClient());
     // Shim in a service required from the colorbox module.
     $colorbox_mock = $this->getMockBuilder('ColorboxAttachment')->setMethods(['attach'])->getMock();
     $this->container->set('colorbox.attachment', $colorbox_mock);
 }
開發者ID:badelas,項目名稱:afroweb,代碼行數:18,代碼來源:KernelTestBase.php

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

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


注:本文中的Drupal\Core\Entity\Entity\EntityViewDisplay類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。