function EntityMethodConfigActionsTest::testRemoveComponentFromDisplay

@testWith ["hideComponent"]
["hideComponents"]

File

core/tests/Drupal/KernelTests/Core/Recipe/EntityMethodConfigActionsTest.php, line 161

Class

EntityMethodConfigActionsTest
@group Recipe

Namespace

Drupal\KernelTests\Core\Recipe

Code

public function testRemoveComponentFromDisplay(string $action_name) : void {
  $this->assertStringStartsWith('hideComponent', $action_name);
  /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $repository */
  $repository = $this->container
    ->get(EntityDisplayRepositoryInterface::class);
  $view_display = $repository->getViewDisplay('entity_test_with_bundle', 'test');
  $this->assertIsArray($view_display->getComponent('name'));
  // The `hideComponent` action is an alias for `removeComponent`, proving
  // that entity methods can be aliased.
  $this->configActionManager
    ->applyAction("entity_method:core.entity_view_display:{$action_name}", $view_display->getConfigDependencyName(), $action_name === 'hideComponents' ? [
    'name',
  ] : 'name');
  $view_display = $repository->getViewDisplay('entity_test_with_bundle', 'test');
  $this->assertNull($view_display->getComponent('name'));
  // The underlying action name should not be available. It should be hidden
  // by the alias.
  $plugin_id = str_replace('hide', 'remove', $action_name);
  $this->assertFalse($this->configActionManager
    ->hasDefinition($plugin_id));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.