View source
<?php
function wbm2cm_install() {
if (!\Drupal::moduleHandler()
->moduleExists('workbench_moderation')) {
return;
}
$state = \Drupal::state();
$collector = \Drupal::service('wbm2cm.workflow_collector');
$state
->set('moderation_workflows', $collector
->getWorkflows());
$entity_types = [];
foreach ($collector
->supported() as $bundle) {
array_push($entity_types, $bundle
->getEntityType()
->getBundleOf());
}
$state
->set('moderation_entity_types', array_unique($entity_types));
$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);
}
function wbm2cm_uninstall() {
\Drupal::state()
->deleteMultiple([
'moderation_entity_types',
'moderation_fields',
'moderation_filters',
'moderation_workflows',
]);
}