You are here

function lightning_workflow_update_8005 in Lightning Workflow 8.3

Same name and namespace in other branches
  1. 8 lightning_workflow.install \lightning_workflow_update_8005()
  2. 8.2 lightning_workflow.install \lightning_workflow_update_8005()

Updates the moderation_history view to work with Content Moderation.

File

./lightning_workflow.install, line 75
Contains installation and update routines for Lightning Workflow.

Code

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();
}