function EntityDisplayTest::testGetDisplayModeOptions
Same name in other branches
- 8.9.x core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::testGetDisplayModeOptions()
- 10 core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::testGetDisplayModeOptions()
- 11.x core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::testGetDisplayModeOptions()
Tests getDisplayModeOptions().
File
-
core/
modules/ field_ui/ tests/ src/ Kernel/ EntityDisplayTest.php, line 484
Class
- EntityDisplayTest
- Tests the entity display configuration entities.
Namespace
Drupal\Tests\field_ui\KernelCode
public function testGetDisplayModeOptions() {
NodeType::create([
'type' => 'article',
])->save();
EntityViewDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'article',
'mode' => 'default',
])->setStatus(TRUE)
->save();
$display_teaser = EntityViewDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'article',
'mode' => 'teaser',
]);
$display_teaser->save();
EntityFormDisplay::create([
'targetEntityType' => 'user',
'bundle' => 'user',
'mode' => 'default',
])->setStatus(TRUE)
->save();
$form_display_teaser = EntityFormDisplay::create([
'targetEntityType' => 'user',
'bundle' => 'user',
'mode' => 'register',
]);
$form_display_teaser->save();
// Test getViewModeOptionsByBundle().
$view_modes = \Drupal::service('entity_display.repository')->getViewModeOptionsByBundle('node', 'article');
$this->assertEquals([
'default' => 'Default',
], $view_modes);
$display_teaser->setStatus(TRUE)
->save();
$view_modes = \Drupal::service('entity_display.repository')->getViewModeOptionsByBundle('node', 'article');
$this->assertEquals([
'default' => 'Default',
'teaser' => 'Teaser',
], $view_modes);
// Test getFormModeOptionsByBundle().
$form_modes = \Drupal::service('entity_display.repository')->getFormModeOptionsByBundle('user', 'user');
$this->assertEquals([
'default' => 'Default',
], $form_modes);
$form_display_teaser->setStatus(TRUE)
->save();
$form_modes = \Drupal::service('entity_display.repository')->getFormModeOptionsByBundle('user', 'user');
$this->assertEquals([
'default' => 'Default',
'register' => 'Register',
], $form_modes);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.