0

Context: I created a new content type (press room nodetype) locally and made a feature with it so it is easier to deploy on my dev-stage-prod environments. This works perfectly well. The thing is, is I need to add permissions to some user roles right away in the same deployment process. I can't find the proper way to run some code after the feature-revert-all;

At the moment I put my code in a new module press_room.install.

function press_room_update_7001() {
    module_enable(['press_room_nodetype']); // installs the feature that will add the new content type

    $permission = [
        'edit any press_room content' => true,
    ];
    _add_permission_to_role('myrole',$permission); // too soon, content type not yet created
}

This module is enabled by another .install (homepage).

function homepage_update_7003() {
    module_enable(['press_room']);
}

With this code the new content type is created and the module to preprocess its output is enabled but the permissions are not given. It seems the content type is not (fully) created when the permissions needs to be added, so Drupal skips those lines and do nothing. If I run my code a second time, it works since the content type already exists.

Has anyone a solution to process code after a new content type has been created. What is the proper way to do this? Thank you.

1 Answer 1

1

This may not be what you're looking for but here is what we do to deploy on several production sites.

  1. Store as much in Features as possible
  2. Write update scripts when needed (as you've done). However, we enable modules via drush, never in code.
  3. then run: drush en feature_module_name -y && drush updb
    • If multiple modules need to be enabled, we normal setup a chain of dependencies in the *.info files.

Your Answer

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

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