lightning_workflow.install in Lightning Workflow 8.2
Same filename and directory in other branches
Contains installation and update routines for Lightning Workflow.
File
lightning_workflow.installView source
<?php
/**
* @file
* Contains installation and update routines for Lightning Workflow.
*/
use Drupal\Core\Config\ImmutableConfig;
use Drupal\node\Entity\NodeType;
use Drupal\workflows\Entity\Workflow;
/**
* Implements hook_install().
*/
function lightning_workflow_install() {
if (\Drupal::moduleHandler()
->moduleExists('lightning_roles')) {
lightning_workflow_modules_installed([
'lightning_roles',
]);
}
// Stop here during a config sync.
if (\Drupal::isConfigSyncing()) {
return;
}
$workflow = Workflow::load('editorial');
$configuration = $workflow
->get('type_settings');
$configuration['states']['review'] = [
'label' => 'In review',
'weight' => -1,
'published' => FALSE,
'default_revision' => FALSE,
];
// Anything in the review state can be sent back to draft, kept in review,
// or published.
$configuration['transitions']['review'] = [
'label' => 'Send to review',
'from' => [
'draft',
'review',
],
'to' => 'review',
'weight' => 0,
];
$configuration['transitions']['create_new_draft']['from'][] = 'review';
$configuration['transitions']['publish']['from'][] = 'review';
// Give the archived_published transition a clearer name.
$configuration['transitions']['archived_published']['label'] = 'Restore from archive';
// Allow transitioning from the archived to draft states, rendering the
// archived_draft transition redundant.
unset($configuration['transitions']['archived_draft']);
$configuration['transitions']['create_new_draft']['from'][] = 'archived';
$workflow
->set('type_settings', $configuration);
$workflow
->save();
foreach (NodeType::loadMultiple() as $node_type) {
lightning_workflow_node_type_insert($node_type);
}
}
/**
* Removed in Lightning 8.x-2.17.
*
* Formerly applied workflow permissions to content management roles.
*
* @deprecated
*/
function lightning_workflow_update_8001() {
}
/**
* Clears the entity type definition cache.
*/
function lightning_workflow_update_8002() {
\Drupal::entityTypeManager()
->clearCachedDefinitions();
}
/**
* Removed in Lightning Workflow 8.x-1.0.
*
* Formerly installed the Lightning Scheduled Updates sub-component.
*
* @deprecated
*/
function lightning_workflow_update_8003() {
}
/**
* Removes the latest_revision__node relationship from the content view.
*/
function lightning_workflow_update_8004() {
$config = \Drupal::configFactory()
->getEditable('views.view.content');
if ($config
->isNew()) {
return;
}
foreach (array_keys($config
->get('display')) as $display_id) {
$config
->clear("display.{$display_id}.display_options.relationships.latest_revision__node");
$config
->clear("display.{$display_id}.display_options.fields.forward_revision_exists");
}
$config
->save();
}
/**
* Updates the moderation_history view to work with Content Moderation.
*/
function lightning_workflow_update_8005() {
$config = \Drupal::configFactory()
->getEditable('views.view.moderation_history');
if ($config
->isNew()) {
return;
}
$entity_type_manager = \Drupal::entityTypeManager();
$display_options = 'display.default.display_options';
// Add a relationship to the moderation state.
$key = "{$display_options}.relationships.moderation_state";
$relationship = $config
->get($key);
if (empty($relationship)) {
$config
->set($key, [
'id' => 'moderation_state',
'table' => $entity_type_manager
->getDefinition('node')
->getRevisionDataTable(),
'field' => 'moderation_state',
'relationship' => 'none',
'group_type' => 'group',
'admin_label' => 'Moderation state',
'required' => TRUE,
'entity_type' => 'node',
'plugin_id' => 'standard',
]);
}
// Update the nid argument, if it exists.
$key = "{$display_options}.arguments.nid";
$argument = $config
->get($key);
if ($argument) {
$argument['default_action'] = 'default';
$argument['default_argument_type'] = 'node';
$argument['default_argument_options'] = [];
$config
->set($key, $argument);
}
// Update the moderation_state field, if it exists.
$key = "{$display_options}.fields.moderation_state";
$field = $config
->get($key);
if ($field) {
$field['table'] = $entity_type_manager
->hasDefinition('content_moderation_state') ? $entity_type_manager
->getDefinition('content_moderation_state')
->getRevisionDataTable() : 'content_moderation_state_field_revision';
$field['relationship'] = 'moderation_state';
$field['admin_label'] = 'Moderation state';
$field['click_sort_column'] = 'value';
$field['type'] = 'content_moderation_state';
$field['settings'] = [];
$field['group_column'] = 'value';
$field['entity_type'] = 'content_moderation_state';
$config
->set($key, $field);
}
// Update the path of the page display, if it exists.
$key = 'display.page.display_options';
$display = $config
->get($key);
if ($display) {
$display['path'] = str_replace('node/%/', 'node/%node/', $display['path']);
$config
->set($key, $display);
}
$config
->save();
}
Functions
Name | Description |
---|---|
lightning_workflow_install | Implements hook_install(). |
lightning_workflow_update_8001 | Removed in Lightning 8.x-2.17. |
lightning_workflow_update_8002 | Clears the entity type definition cache. |
lightning_workflow_update_8003 | Removed in Lightning Workflow 8.x-1.0. |
lightning_workflow_update_8004 | Removes the latest_revision__node relationship from the content view. |
lightning_workflow_update_8005 | Updates the moderation_history view to work with Content Moderation. |