In a hook_install implementation, I need to change the entity view display configuration of certain bundle / view mode combinations. For instance, I would like to change the 'teaser' view mode of the 'article' bundle and hide 'field_image'.
When you export the configuration, you'll see those settings stored in
core.entity_view_display.node.article.teaser.yml. I know it's possible to load the configuration like this:
$view_mode_config = \Drupal::configFactory()->getEditable('core.entity_view_display.node.article.default');
This would allow you to change and save the config object, but I suppose that is not the correct way to do it. I'm guessing there must be some kind of view mode manager class I should use to do this, but I haven't been able to find it.
So how do I change the entity view display configuration programmatically?
Bonus question: When you find yourself in a situation like this, what are your strategies to explore the code and find the classes you need?