3

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?
  • But during installation that tells me that the frontpage view doesn't exist did you try installing your module in a fresh/vanilla Drupal install? I only ask since your answer worked for Darol. So either something changed since '16 or something is going on with your Drupal. – No Sssweat May 17 '18 at 6:08
  • @NoSssweat I did - the content View isn’t optional conf, I wonder if that’s the difference – Clive May 17 '18 at 6:50
1

Hmm, have you tried in the .profile file an hook_install_tasks?

Or maybe with the hook_install_tasks_alter.

/**
 * Implements hook_install_tasks_alter().
 */
function MODULE_install_tasks_alter(array &$tasks, array $install_state) {
  $tasks['install_finished']['function'] = 'CALLBACK_post_install';
}

And deactivate the view in the callback.

  • 1
    Turns out hook_install is the best place to do this, but moving it to the install profile was definitely the way to go. Thanks – Clive Jun 4 '18 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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