0

I have added a new field to an existing content type and want to set its default value as well as all existing nodes of that type.

To do that, I have added an update hook in my module that will batch process nodes of this type and set the value to true.

Although if this runs before config import, it will fail since the field does not exist yet.

Is there a way to prevent the update hook from processing until specific config has imported?

I added this in the update hook, but I am not sure if that would be effective enough:

if (!$node->hasField('field_show_generic_listing')) {
  throw new UpdateException('Cannot continue - import the latest configuration to add the new field to this node type.');
}
  • 1
    Have you tested it? I am not sure if that would be effective enough you might be right, Your hook update N could be marked as runned if config hasn't been imported yet and won't run again in the future. Although I think the throw new UpdateException might prevent it from being marked as runned by the system. Test! – No Sssweat Feb 8 at 15:05

Your Answer

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

Browse other questions tagged or ask your own question.