function lightning_workflow_node_type_insert in Lightning Workflow 8.2
Same name and namespace in other branches
- 8.3 lightning_workflow.module \lightning_workflow_node_type_insert()
- 8 lightning_workflow.module \lightning_workflow_node_type_insert()
Implements hook_ENTITY_TYPE_insert().
3 calls to lightning_workflow_node_type_insert()
- lightning_workflow_install in ./
lightning_workflow.install - Implements hook_install().
- lightning_workflow_modules_installed in ./
lightning_workflow.module - Implements hook_modules_installed().
- ModerationContext::addModerationToContentType in tests/
contexts/ ModerationContext.behat.inc - Enables moderation for a content type.
File
- ./
lightning_workflow.module, line 27 - Provides workflow enhancements for Drupal.
Code
function lightning_workflow_node_type_insert(NodeTypeInterface $node_type) {
// Don't do anything during a config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
$workflow = $node_type
->getThirdPartySetting('lightning_workflow', 'workflow');
if (empty($workflow)) {
return;
}
$workflow = Workflow::load($workflow);
if (empty($workflow)) {
return;
}
$plugin = $workflow
->getTypePlugin();
if ($plugin instanceof ContentModerationInterface) {
$rebuild = !in_array('node', $plugin
->getEntityTypes(), TRUE);
$plugin
->addEntityTypeAndBundle('node', $node_type
->id());
$workflow
->save();
// We need to rebuild all routes because Content Moderation needs to ensure
// that edit forms load the latest revision.
if ($rebuild) {
Drupal::service('router.builder')
->rebuild();
}
}
}