How do I stop a module from installing optional configuration, or make sure it's installed by the time I want to remove it myself?

by Clive   Last Updated May 16, 2018 13:07 PM

I don't want the "Frontpage" view to be installed along with my installation profile.

I tried adding a hook_install to a module which does this:

\Drupal::entityTypeManager()->getStorage('view')
  ->load('frontpage')
  ->setStatus(FALSE)
  ->save(); 

But during installation that tells me that the frontpage view doesn't exist when my module is being installed. Fair enough, so I added the module that owns the frontpage view config (core node) to my dependencies:

dependencies:
  ...
  - drupal:node

Still didn't work. Then I realised it's optional config; maybe the module responsible for processing that config (core views) also needs to be a dependency. It would make sense, so my dependencies became:

dependencies:
  ...
  - drupal:node
  - drupal:views

Still didn't work, same problem - the View simply doesn't exist yet, so it can't be deleted.

So two halves of the same question:

  1. How do I stop this config from ever having been installed in the first place (or installed but initially disabled)?
  2. If that's not possible, what dependencies do I need to provide to ensure that the View in question is installed by the time my own hook_install is executed, so I can remove/disable it myself?


Related Questions


Enabling modules through configuration

Updated August 23, 2017 13:07 PM

BLT + Contenta CMS

Updated February 20, 2018 18:07 PM