You are here

wbm2cm.install in Workbench Moderation to Content Moderation 8.2

Same filename and directory in other branches
  1. 8 wbm2cm.install

File

wbm2cm.install
View source
<?php

/**
 * Implements hook_install().
 */
function wbm2cm_install() {
  if (!\Drupal::moduleHandler()
    ->moduleExists('workbench_moderation')) {
    return;
  }
  $state = \Drupal::state();

  /** @var \Drupal\wbm2cm\WorkflowCollector $collector */
  $collector = \Drupal::service('wbm2cm.workflow_collector');
  $state
    ->set('moderation_workflows', $collector
    ->getWorkflows());
  $entity_types = [];

  /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $bundle */
  foreach ($collector
    ->supported() as $bundle) {
    array_push($entity_types, $bundle
      ->getEntityType()
      ->getBundleOf());
  }
  $state
    ->set('moderation_entity_types', array_unique($entity_types));

  // Find every Views filter and field which filter by, or display, the
  // moderation state.
  $filters = $fields = [];
  $views = \Drupal::configFactory()
    ->listAll('views.view');
  foreach ($views as $view_id) {
    $view = \Drupal::config($view_id);
    $displays = $view
      ->get('display');
    foreach ($displays as $display_id => $display) {
      if (isset($display['display_options']['filters'])) {
        foreach ($display['display_options']['filters'] as $filter_id => $filter) {
          if (isset($filter['entity_field']) && $filter['entity_field'] == 'moderation_state') {
            array_push($filters, [
              $view_id,
              $display_id,
              $filter_id,
            ]);
          }
        }
      }
      if (isset($display['display_options']['fields'])) {
        foreach ($display['display_options']['fields'] as $field_id => $field) {
          if (isset($field['entity_field']) && $field['entity_field'] == 'moderation_state') {
            array_push($fields, [
              $view_id,
              $display_id,
              $field_id,
            ]);
          }
        }
      }
    }
  }
  $state
    ->set('moderation_filters', $filters);
  $state
    ->set('moderation_fields', $fields);
}

/**
 * Implements hook_uninstall().
 */
function wbm2cm_uninstall() {
  \Drupal::state()
    ->deleteMultiple([
    'moderation_entity_types',
    'moderation_fields',
    'moderation_filters',
    'moderation_workflows',
  ]);
}

Functions

Namesort descending Description
wbm2cm_install Implements hook_install().
wbm2cm_uninstall Implements hook_uninstall().