You are here

lightning_workflow.install in Lightning Workflow 8.3

Same filename and directory in other branches
  1. 8 lightning_workflow.install
  2. 8.2 lightning_workflow.install

Contains installation and update routines for Lightning Workflow.

File

lightning_workflow.install
View source
<?php

/**
 * @file
 * Contains installation and update routines for Lightning Workflow.
 */
use Drupal\node\Entity\NodeType;

/**
 * Implements hook_install().
 */
function lightning_workflow_install() {

  // Stop here during a config sync.
  if (Drupal::isConfigSyncing()) {
    return;
  }
  $modules = [
    'autosave_form',
    'lightning_roles',
  ];
  $modules = array_filter($modules, [
    Drupal::moduleHandler(),
    'moduleExists',
  ]);
  if ($modules) {
    lightning_workflow_modules_installed($modules);
  }
  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.
 */
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.
 */
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';

  // 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
      ->getDefinition('node')
      ->getRevisionDataTable();
    $field['relationship'] = 'none';
    $field['admin_label'] = 'Moderation state';
    $field['click_sort_column'] = 'value';
    $field['type'] = 'content_moderation_state';
    $field['settings'] = [];
    $field['group_column'] = 'value';
    $field['entity_type'] = 'node';
    $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();
}

/**
 * Removes deprecated relationship from moderation_history view.
 */
function lightning_workflow_update_8006() {
  $config = Drupal::configFactory()
    ->getEditable('views.view.moderation_history');
  if ($config
    ->isNew()) {
    return;
  }
  $display_options = 'display.default.display_options';

  // Delete the deprecated relationship to the moderation state.
  $config
    ->clear("{$display_options}.relationships.moderation_state");

  // The moderation_state field should not use the deprecated moderation_state
  // relationship.
  $key = "{$display_options}.fields.moderation_state";
  $field = $config
    ->get($key);
  if ($field) {
    $field['table'] = Drupal::entityTypeManager()
      ->getDefinition('node')
      ->getRevisionDataTable();
    $field['relationship'] = 'none';
    $field['entity_type'] = 'node';
    unset($field['entity_field']);
    $config
      ->set($key, $field);
  }
  $config
    ->save();
}

Functions

Namesort descending 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.
lightning_workflow_update_8006 Removes deprecated relationship from moderation_history view.