I develop a contrib module. I added a new field to "user" entity. I need to hide this field from display in "manage display"

I run this code

$entity_view_display = \Drupal::entityTypeManager()
if ($entity_view_display) {
  $entity_view_display->setComponent('field_myfield', [
    'region' => 'hidden',

In "manage display" page (/admin/config/people/accounts/display) I see that my field moved to "hidden" region, but when I view user profile I see my field.

If I press "save" button in "manage display" page my field is gone when I view user profile.

How to resave "manage display" programmatically? Is it possible?

1 Answer 1


You can use EntityDisplayBase::removeComponent():

  • It works, thanks!
    – Vanish
    Aug 7, 2023 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.