workflow-8.x-1.x-dev/workflow.install
workflow.install
<?php
/**
* @file
* Install, update and uninstall functions for the workflow module.
*/
use Drupal\Core\Url;
use Drupal\workflow\Entity\WorkflowManager;
/**
* Implements hook_install().
*/
function workflow_install() {
$url = Url::fromRoute('user.admin_permissions', [],
['fragment' => 'module-workflow']);
$message = t("Thanks for using Workflow module.
To start using a Workflow, first create a Workflow type,
then add a Workflow State field to your entity.
Please review which roles may 'participate in workflows'
<a href=':url'>on the Permissions page</a>.",
[':url' => $url->toString()]);
\Drupal::messenger()->addStatus($message);
}
/**
* Update from version beta1 to beta2 are not possible. Please re-install this module.
*/
function workflow_update_8001(&$sandbox) {
\Drupal::messenger()->addStatus("Update from version beta1 to beta2 is not possible. Please re-install this module.");
}
/**
* Please check Workflow permissions "Revert own\/any state transition' and "Edit own\/any comments" before continuing.
*/
function workflow_update_8002(&$sandbox) {
\Drupal::messenger()->addStatus("Please check Workflow permissions 'Revert own/any state transition and 'Edit own/any comments' before continuing.");
}
/**
* This will optionally install a History View and an Action.
*/
function workflow_update_8003(&$sandbox) {
// In version 8.x-1.8.
}
/**
* This will fix the Error 'Mismatched entity and/or field definitions' on /admin/reports/status.
*/
function workflow_update_8012(&$sandbox) {
$entity_type_manager = \Drupal::entityTypeManager();
$entity_type_manager->clearCachedDefinitions();
$entity_type_ids = [];
$change_summary = \Drupal::service('entity.definition_update_manager')->getChangeSummary();
foreach ($change_summary as $entity_type_id => $change_list) {
if (WorkflowManager::isWorkflowEntityType($entity_type_id)) {
$entity_type = $entity_type_manager->getDefinition($entity_type_id);
// Apparently we must 'install', not 'update'.
// Check page admin/reports/status afterwards.
\Drupal::entityDefinitionUpdateManager()->installEntityType($entity_type);
// \Drupal::entityDefinitionUpdateManager()->updateEntityType($entity_type);
// $field_storage_definitions = [];
// \Drupal::entityDefinitionUpdateManager()->updateFieldableEntityType($entity_type, $field_storage_definitions, $sandbox);
$entity_type_ids[] = $entity_type_id;
}
}
if ($entity_type_ids) {
drupal_flush_all_caches();
return t("Updated the entity type(s): @entity_type_ids", [
'@entity_type_ids' => implode(', ', $entity_type_ids),
]);
}
}
/**
* Updates existing configuration to match configuration schema.
*/
function workflow_update_8009(&$sandbox) {
// In version 2.1.0. and 2.1.5
// Remove configuration that was introduced in update_8003.
$config_names = [
'block.block.workflowtransitionform',
'system.action.change_a_node_to_next_workflow_state',
'system.action.change_a_node_to_new_workflow_state',
];
foreach ($config_names as $config_name) {
\Drupal::configFactory()->getEditable($config_name)->delete();
}
}
