You are here

public function FieldFormatterContext::iHideTheDisplayOfTheFieldOfTheBundleOfEntity in Views field formatter 8.2

Hide the display of a field.

@Given I hide the display of the :field field of the :bundle bundle of :entity entity @Given I hide the display of the :field field of the :bundle bundle of :entity entity in :view_mode view mode

File

tests/Behat/FieldFormatterContext.php, line 48

Class

FieldFormatterContext
Class FieldFormatterContext.

Namespace

Drupal\Tests\views_field_formatter\Behat

Code

public function iHideTheDisplayOfTheFieldOfTheBundleOfEntity($field, $bundle, $entity, $view_mode = 'default') {
  $config_name = \sprintf('core.entity_view_display.%s.%s.%s', $entity, $bundle, $view_mode);
  $config = \Drupal::configFactory()
    ->getEditable($config_name)
    ->getRawData();
  if (!isset($config['content'][$field])) {

    // @todo Throw an error.
    return;
  }
  unset($config['content'][$field]);
  $config['hidden'][$field] = TRUE;
  \Drupal::configFactory()
    ->getEditable($config_name)
    ->setData($config)
    ->save();
}