contrib modules updates

This commit is contained in:
2019-02-27 10:39:59 +01:00
parent 04a4b8895d
commit e3cf889820
579 changed files with 18343 additions and 4076 deletions
@@ -44,10 +44,10 @@ class WorkflowAccessRoleForm extends WorkflowConfigTransitionFormBase {
*/
public function buildHeader() {
$header = [
'label_new' => t('State'),
'view' => t('Roles who can view posts in this state'),
'update' => t('Roles who can edit posts in this state'),
'delete' => t('Roles who can delete posts in this state'),
'label_new' => $this->t('State'),
'view' => $this->t('Roles who can view posts in this state'),
'update' => $this->t('Roles who can edit posts in this state'),
'delete' => $this->t('Roles who can delete posts in this state'),
];
return $header;
}
@@ -93,7 +93,7 @@ class WorkflowAccessRoleForm extends WorkflowConfigTransitionFormBase {
$row['label_new'] = [
'#type' => 'value',
'#markup' => t('@label', ['@label' => $state->label()]),
'#markup' => $this->t('@label', ['@label' => $state->label()]),
];
$row['view'] = [
'#type' => 'checkboxes',
@@ -34,7 +34,7 @@ class WorkflowAccessSettingsForm extends ConfigFormBase {
$form['workflow_access'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => t('Workflow Access Settings'),
'#title' => $this->t('Workflow Access Settings'),
];
$form['workflow_access']['#tree'] = TRUE;
@@ -42,11 +42,13 @@ class WorkflowAccessSettingsForm extends ConfigFormBase {
$form['workflow_access']['workflow_access_priority'] = [
'#type' => 'weight',
'#delta' => 10,
'#title' => t('Workflow Access Priority'),
'#title' => $this->t('Workflow Access Priority'),
'#default_value' => $weight,
'#description' => t('This sets the node access priority. Changing this
setting can be dangerous. If there is any doubt, leave it at 0.
<a href=":url" target="_blank">Read the manual</a>.', [':url' => $url]),
'#description' => $this->t(
'This sets the node access priority. Changing this setting can be
dangerous. If there is any doubt, leave it at 0.
<a href=":url" target="_blank">Read the manual</a>.',
[':url' => $url]),
];
return parent::buildForm($form, $form_state);
@@ -1,13 +1,14 @@
name: 'Workflow access'
name: Workflow Access
type: module
description: 'Content access control based on workflows and roles. Depends on the node_access system, so only works for entities of type ''node''.'
dependencies:
- workflow
package: Workflow
# core: 8.x
type: module
dependencies:
- workflow:workflow
configure: entity.workflow_type.collection
# Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1+18-dev'
# Information added by Drupal.org packaging script on 2019-01-29
version: '8.x-1.1+35-dev'
core: '8.x'
project: 'workflow'
datestamp: 1536080308
datestamp: 1548801486
@@ -22,30 +22,34 @@ function workflow_access_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'entity.workflow_type.access_form':
$url = \Drupal\Core\Url::fromRoute('workflow.access.settings');
$output .= t("This page lets you refine the permissions per role and per
workflow state. Although the workflow module allows you to add multiple
workflows to per entity type, Workflow Access supports only one
workflow per entity type."
$output .= t(
'This page lets you refine the permissions per role and per
workflow state. Although the workflow module allows you to add multiple
workflows to per entity type, Workflow Access supports only one
workflow per entity type.'
);
$output .= "<br>";
$output .= t("WARNING: Use of the 'Edit any', 'Edit own', and even 'View
published content' permissions for the content type may override these
access settings. You may disable those permissions or
<a href=':url'>alter the priority of
$output .= t(
"WARNING: Use of the 'Edit any', 'Edit own', and even 'View
published content' permissions for the content type may override these
access settings. You may disable those permissions or
<a href=':url'>alter the priority of
the Workflow access module</a>.", [':url' => $url->toString()]
);
if (\Drupal::moduleHandler()->moduleExists('og')) {
$output .= '<br>';
$output .= t('WARNING: Organic Groups (OG) is present and may interfere
with these settings.');
$output .= t(
'WARNING: Organic Groups (OG) is present and may interfere
with these settings.'
);
//$output .= ' ';
//$url = \Drupal\Core\Url::fromUri('admin/config/group/settings'); // @todo D8: FIXME when OG module is ported.
//$output .= t("In particular, if <a href=':url'>Strict node access
// permissions</a> is enabled, since this may override Workflow access
// settings.", [':url' => $url]);
$output .= t("In particular, if <i>Strict node access
permissions</i> is enabled, since this may override Workflow access
settings.");
$output .= t(
'In particular, if <i>Strict node access permissions</i> is enabled,
since this may override Workflow access settings.');
}
break;
@@ -126,16 +130,11 @@ function workflow_access_get_role_gid($rid) {
// $roles_gids = $config->get('content_access_roles_gids');
// return $roles_gids[$role];
// Return a weight, avoiding negative values by starting with 100.
// For 'Author', no role exists.
/* @var $role Role */
$role = \Drupal\user\Entity\Role::load($rid);
$weight = 100; // Avoid negative values.
if ($role) {
$weight += $role->getWeight();
}
else {
// For Author, no role exists.
$weight -= 20;
}
$weight = $role ? 100 + $role->getWeight() : 100 - 20;
return $weight;
}
@@ -148,86 +147,86 @@ function workflow_access_get_role_gid($rid) {
*/
function workflow_access_node_access_records(\Drupal\node\NodeInterface $node) {
$grants = [];
$workflow_transitions_added = FALSE;
//if (!$node->isPublished()) {
// // @todo: return;
//}
$entity_type = $node->getEntityTypeId();
// Only relevant for content with Workflow.
if (!isset($node->workflow_transitions)) {
$node->workflow_transitions = [];
// Sometimes, a node is saved without going through workflow_transition_form.
// E.g.,
// - when saving a node with workflow_node programmatically with node_save();
// - when changing a state on a node view page/history tab;
// - when rebuilding permissions via batch for Workflow Fields.
// In that case, we need to create the workflow_transitions ourselves to
// calculate the grants.
foreach (workflow_get_workflow_field_names($node, $entity_type) as $field_name) {
$old_sid = $new_sid = $node->$field_name->value;
// Create a dummy transition, just to set $node->workflow_transitions.
if ($old_sid) {
/* @var $transition WorkflowTransitionInterface */
$transition = WorkflowTransition::create([$old_sid, 'field_name' => $field_name]);
$transition->setTargetEntity($node);
$transition->setValues($new_sid, $node->getOwnerId(), \Drupal::time()->getRequestTime(), '');
// Store the transition, so it can be easily fetched later on.
// Store in an array, to prepare for multiple workflow_fields per entity.
// This is a.o. used in hook_entity_update to trigger 'transition post'.
$node->workflow_transitions[$field_name] = $transition;
$workflow_transitions_added = TRUE;
}
}
if (!$workflow_field_names = workflow_get_workflow_field_names($node, $node->getEntityTypeId())) {
return $grants;
}
// Get 'author' of this entity.
// - Some entities (e.g., taxonomy_term) do not have a uid.
// But then again: node_access is only for nodes...
$uid = ($node->getOwnerId()) ? (int) $node->getOwnerId() : 0;
// Create grants for each translation of the node.
$priority = workflow_access_get_setting('workflow_access_priority');
foreach ($node->getTranslationLanguages() as $langcode => $language) {
$translation = $node->getTranslation($langcode);
$count = 0;
foreach ($node->workflow_transitions as $transition) {
// @todo: add support for +1 workflows per entity.
if ($count++ == 1) {
continue;
// @todo: how to handle not published entities?
// if (!$translation->isPublished()) {
// return;
// }
// Get 'author' of this entity. Some entities (e.g., taxonomy_term)
// do not have a uid. But then again: node_access is only for nodes...
$uid = ($translation->getOwnerId()) ? (int) $translation->getOwnerId() : 0;
$workflow_transitions = [];
if (isset($translation->workflow_transitions)) {
$workflow_transitions = $translation->workflow_transitions;
}
else {
// Sometimes, a node is saved without going through workflow_transition_form.
// E.g.,
// - when saving a node with workflow_node programmatically with node_save();
// - when changing a state on a node view page/history tab;
// - when rebuilding permissions via batch for Workflow Fields.
// In that case, we need to create the workflow_transitions ourselves to
// calculate the grants.
foreach ($workflow_field_names as $field_name) {
// Create a dummy transition, just to set $workflow_transitions.
$old_sid = $new_sid = $translation->{$field_name}->value;
if ($old_sid) {
/* @var $transition WorkflowTransitionInterface */
$transition = WorkflowTransition::create([$old_sid, 'field_name' => $field_name]);
$transition->setTargetEntity($translation);
$transition->setValues($new_sid, $translation->getOwnerId(), \Drupal::time()->getRequestTime(), '');
$workflow_transitions[$field_name] = $transition;
}
}
}
$field_name = $transition->getFieldName();
if ($current_sid = workflow_node_current_state($node, $field_name)) {
foreach (workflow_access_get_workflow_access_by_sid($current_sid) as $rid => $grant) {
$realm = ($uid > 0 && $rid == WORKFLOW_ROLE_AUTHOR_RID) ? 'workflow_access_owner' : 'workflow_access';
$gid = ($uid > 0 && $rid == WORKFLOW_ROLE_AUTHOR_RID) ? $uid : workflow_access_get_role_gid($rid);
$count_workflow_fields = 0;
foreach ($workflow_transitions as $field_name => $transition) {
// @todo: add support for +1 workflows per entity.
if (++$count_workflow_fields > 1) {
continue;
}
// Anonymous ($uid == 0) author is not allowed for role 'author' (== -1).
if (!$current_sid = workflow_node_current_state($translation, $field_name)) {
continue;
}
foreach (workflow_access_get_workflow_access_by_sid($current_sid) as $rid => $grant) {
// Anonymous ($uid == 0) author is not allowed for role 'Author' (== -1).
// Both logically (Anonymous having more rights then authenticated)
// and technically: $gid must be a positive int.
// and technically ($gid must be a positive integer).
if ($uid == 0 && $rid == WORKFLOW_ROLE_AUTHOR_RID) {
continue;
}
$grants[] = [
'realm' => $realm,
'gid' => $gid,
'realm' => ($uid > 0 && $rid == WORKFLOW_ROLE_AUTHOR_RID)
? 'workflow_access_owner' : 'workflow_access',
'gid' => ($uid > 0 && $rid == WORKFLOW_ROLE_AUTHOR_RID)
? $uid : workflow_access_get_role_gid($rid),
'grant_view' => (int) $grant['grant_view'],
'grant_update' => (int) $grant['grant_update'],
'grant_delete' => (int) $grant['grant_delete'],
'priority' => $priority,
// 'langcode' => $node->language(),
'langcode' => $langcode,
'field_name' => $field_name, // Just for analysis and info.
];
}
}
}
if ($workflow_transitions_added == TRUE) {
unset($node->workflow_transitions);
}
return $grants;
}
@@ -241,12 +240,16 @@ function workflow_access_node_access_explain($row) {
static $interpretations = [];
switch ($row->realm) {
case 'workflow_access_owner':
$interpretations[$row->gid] = t('Workflow access: author of the content may access');
$interpretations[$row->gid] = t(
'Workflow access: author of the content may access'
);
break;
case 'workflow_access':
$roles = user_roles();
$interpretations[$row->gid] = t('Workflow access: %role may access', ['%role' => $roles[$row->gid]]);
$interpretations[$row->gid] = t(
'Workflow access: %role may access', ['%role' => $roles[$row->gid]]
);
break;
}
return (!empty($interpretations[$row->gid]) ? $interpretations[$row->gid] : NULL);
@@ -52,9 +52,11 @@ class WorkflowCleanupSettingsForm extends FormBase {
$form['no_workflow'] = [
'#type' => 'details',
'#title' => t('Orphaned States'),
'#title' => $this->t('Orphaned States'),
'#open' => TRUE, // Controls the HTML5 'open' attribute. Defaults to FALSE.
'#description' => t('These states no longer belong to an existing workflow.'),
'#description' => $this->t(
'These states no longer belong to an existing workflow.'
),
'#tree' => TRUE,
];
foreach ($orphans as $sid => $state) {
@@ -67,9 +69,11 @@ class WorkflowCleanupSettingsForm extends FormBase {
$form['inactive'] = [
'#type' => 'details',
'#title' => t('Inactive (Deleted) States'),
'#title' => $this->t('Inactive (Deleted) States'),
'#open' => TRUE, // Controls the HTML5 'open' attribute. Defaults to FALSE.
'#description' => t('These states belong to a workflow, but have been marked inactive (deleted).'),
'#description' => $this->t(
'These states belong to a workflow, but have been marked inactive (deleted).'
),
'#tree' => TRUE,
];
foreach ($inactive as $sid => $state) {
@@ -82,7 +86,7 @@ class WorkflowCleanupSettingsForm extends FormBase {
$form['submit'] = [
'#type' => 'submit',
'#value' => t('Delete selected states'),
'#value' => $this->t('Delete selected states'),
];
return $form;
@@ -4,10 +4,11 @@ description: 'Cleans up Workflow cruft. (Do not enable in production sites.)'
package: Workflow
# core: 8.x
dependencies:
- workflow
- workflow:workflow
configure: workflow.cleanup.settings
# Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1+18-dev'
# Information added by Drupal.org packaging script on 2019-01-29
version: '8.x-1.1+35-dev'
core: '8.x'
project: 'workflow'
datestamp: 1536080308
datestamp: 1548801486
@@ -1,14 +1,13 @@
name: 'Workflow Devel'
name: Workflow Devel
type: module
description: 'Tools for developing Workflow add-ons. Calls every hook in workflow.api.php and generates a user message on each call. (Do not enable in production sites.)'
package: Workflow
type: module
# core: 8.x
dependencies:
- workflow
- workflow:workflow
# Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1+18-dev'
# Information added by Drupal.org packaging script on 2019-01-29
version: '8.x-1.1+35-dev'
core: '8.x'
project: 'workflow'
datestamp: 1536080308
datestamp: 1548801486
@@ -1,12 +1,13 @@
name: 'Workflow Field'
name: Workflow Field
type: module
description: 'A residual submodule. No need to enable this module for installations with workflow 8.x-1.0-beta6 and later.'
package: Workflow
type: module
# core: 8.x
hidden: TRUE
# Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1+18-dev'
# Information added by Drupal.org packaging script on 2019-01-29
version: '8.x-1.1+35-dev'
core: '8.x'
project: 'workflow'
datestamp: 1536080308
datestamp: 1548801486
@@ -1,14 +1,13 @@
name: 'Workflow operations'
description: "Adds lesser-used Transition permissions (edit, revert, delete permissions)."
package: Workflow
name: Workflow Operations
type: module
description: 'Adds lesser-used Transition permissions (edit, revert, delete permissions).'
package: Workflow
# core: 8.x
dependencies:
- workflow
- workflow:workflow
# Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1+18-dev'
# Information added by Drupal.org packaging script on 2019-01-29
version: '8.x-1.1+35-dev'
core: '8.x'
project: 'workflow'
datestamp: 1536080308
datestamp: 1548801486
@@ -14,8 +14,6 @@ use Drupal\workflow\Entity\WorkflowState;
*/
class WorkflowStateListBuilder extends DraggableListBuilder {
// @TODO D8-port WorkflowStateListBuilder: enable machine_name: interactive WorkflowState element.
/**
* Load the Transitions, and filter for Workflow type.
* {@inheritdoc}
@@ -23,9 +21,7 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
public function load() {
$entities = [];
// Get the Workflow from the page.
if (!$workflow = workflow_url_get_workflow()) {
// @todo: Generate error message.
return $entities;
}
@@ -46,7 +42,6 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
*/
public function getFormId() {
return 'workflow_state_form';
//return parent::getFormId();
}
/**
@@ -82,13 +77,11 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
public function buildRow(EntityInterface $entity) {
$row = [];
// Get the Workflow from the page.
/** @var $workflow \Drupal\workflow\Entity\Workflow */
if (!$workflow = workflow_url_get_workflow()) {
workflow_debug( __FILE__, __FUNCTION__, __LINE__); // @todo D8-port: still test this snippet.
return $row;
}
$wid = $url_wid = $workflow->id();
$wid = $url_wid = $workflow->id();
/** @var $entity \Drupal\workflow\Entity\WorkflowState */
$state = $entity;
$sid = $state->id();
@@ -101,10 +94,8 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
$state_options += workflow_get_workflow_state_names($wid, FALSE);
// Make it impossible to reassign to the same state that is disabled.
if ($state->isCreationState() || !$sid || !$state->isActive()) {
$current_state_options = [];
}
else {
$current_state_options = [];
if ($state->isActive() && !$state->isCreationState() && $sid) {
$current_state = [$sid => $state_options[$sid]];
$current_state_options = array_diff($state_options, $current_state);
}
@@ -126,6 +117,7 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
'#maxlength' => 255,
'#default_value' => $label,
'#title' => NULL, // This hides the red 'required' asterisk.
'#disabled' => !$state->isActive(),
// '#required' => TRUE,
];
$row['id'] = [
@@ -137,12 +129,12 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
'#default_value' => $state->id(),
// N.B.: Keep machine_name in WorkflowState and ~ListBuilder aligned.
'#required' => FALSE,
// @TODO D8-port: enable machine_name: interactive WorkflowState element.
// @TODO D8-port: enable machine_name as interactive WorkflowState element.
'#machine_name' => [
'exists' => [$this, 'exists'], // Local helper function, at the bottom of this class.
// 'source' => ['label_new'],
// 'source' => ['label_new'],
'source' => ['states', $state->id(), 'label_new'],
// 'replace_pattern' =>'([^a-z0-9_]+)|(^custom$)',
// 'replace_pattern' =>'([^a-z0-9_]+)|(^custom$)',
'replace_pattern' => '[^a-z0-9_()]+', // Added '()' characters from exclusion list since creation state has it.
'error' => $this->t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores.'),
],
@@ -154,6 +146,7 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
$row['status'] = [
'#type' => 'checkbox',
'#default_value' => $state->isActive(),
'#disabled' => $state->isCreationState() || !$sid,
];
// The new value of states that are inactivated.
$row['reassign'] = [
@@ -166,21 +159,11 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
'#markup' => $count,
];
// Disable some properties for Creation state.
if ($state->isCreationState()) {
$row['status']['#disabled'] = TRUE;
$row['reassign']['#type'] = 'hidden';
$row['reassign']['#disabled'] = TRUE;
}
// New state and disabled states cannot be reassigned.
if (!$sid || !$state->isActive() || ($count == 0) ) {
if (!$state->isActive() || $state->isCreationState() || !$sid || !$count) {
$row['reassign']['#type'] = 'hidden';
$row['reassign']['#disabled'] = TRUE;
}
// Disabled states cannot be renamed (and is a visual clue, too).
if (!$state->isActive()) {
$row['label_new']['#disabled'] = TRUE;
}
return $row + parent::buildRow($entity);
}
@@ -189,12 +172,10 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Get the Workflow from the page.
/** @var $workflow \Drupal\workflow\Entity\Workflow */
if (!$workflow = workflow_url_get_workflow()) {
return $form;
}
$wid = $workflow->getWorkflowId();
$form = parent::buildForm($form, $form_state);
// Add a sticky header.
@@ -202,21 +183,35 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
'#sticky' => TRUE,
];
$wid = $workflow->id();
// Build select options for reassigning states.
// We put a blank state first for validation.
$state_options = workflow_get_workflow_state_names($wid, FALSE);
// Is this the last state available?
$form['#last_mohican'] = (count($state_options) == 1);
$form['entities']['#prefix'] = '<div id="states_table_wrapper">';
$form['entities']['#suffix'] = '</div>';
// Create a placeholder WorkflowState (It must NOT be saved to DB). Add it to the item list.
$sid = '';
$placeholder = $workflow->createState($sid, FALSE);
$placeholder->set('label', '');
$this->entities['placeholder'] = $placeholder;
$form['entities']['placeholder'] = $this->buildRow($placeholder);
if ($form_state->getTriggeringElement()['#name'] === 'add_state') {
$sid = '';
$placeholder = $workflow->createState($sid, FALSE);
$placeholder->set('label', '');
$this->entities['placeholder'] = $placeholder;
$form['entities']['placeholder'] = $this->buildRow($placeholder);
}
// Rename 'submit' button.
$form['actions']['submit']['#value'] = t('Save');
// Add 'Add State' button.
$form['actions']['add_state'] = [
'#name' => 'add_state',
'#type' => 'submit',
'#value' => t('Add State'),
'#ajax' => [
'callback' => '::addStateCallback',
'wrapper' => 'states_table_wrapper',
]
];
return $form;
}
@@ -230,8 +225,6 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
/** @var $state \Drupal\workflow\Entity\WorkflowState */
$state = $entity;
// $workflow = $state->getWorkflow();
/**
* Allow modules to insert their own workflow operations to the list.
*/
@@ -251,43 +244,24 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
// @TODO D8-port WorkflowStateListBuilder: enable machine_name as interactive WorkflowState element.
foreach ($form_state->getValue($this->entitiesKey) as $sid => $value) {
if (isset($this->entities[$sid])) {
/** @var $state WorkflowState */
$state = $this->entities[$sid];
/** @var $state WorkflowState */
$state = isset($this->entities[$sid]) ? $this->entities[$sid] : NULL;
// Does user want to deactivate the state (reassign current content)?
if ($sid && $value['status'] == 0 && $state->isActive()) {
workflow_debug( __FILE__, __FUNCTION__, __LINE__, '', ''); // @todo D8-port: still test this snippet.
$args = ['%state' => $state->label()];
// Does that state have content in it?
if ($value['count'] > 0 && empty($value['reassign'])) {
if ($form['#last_mohican']) {
$message = 'Since you are deleting the last available
workflow state in this workflow, all content items
which are in that state will have their workflow state
removed.';
drupal_set_message($this->t($message, $args), 'warning');
}
else {
$message = 'The %state state has content; you must
reassign the content to another state.';
$form_state->setErrorByName("states'][$sid]['reassign'", $this->t($message, $args));
}
}
// State is de-activated (reassigning current content).
if ($state && $state->isActive() && !$value['status']) {
$args = ['%state' => $state->label()];
// Does that state have content in it?
if (!$form['#last_mohican'] && $value['count'] > 0 && empty($value['reassign'])) {
$message = 'The %state state has content; you must
reassign the content to another state.';
$form_state->setErrorByName("states'][$sid]['reassign'", $this->t($message, $args));
}
// Create the machine_name for new states.
// N.B.: Keep machine_name in WorkflowState and ~ListBuilder aligned.
if ($value['label_new'] && !$value['id']) {
//$message = 'Machine name is required.';
//$form_state->setErrorByName('machine_name', $this->t($message));
}
}
}
return;
return [];
}
/**
@@ -297,12 +271,9 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
* The WorkflowState entities are always saved.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// parent::submitForm($form, $form_state);
// Get the Workflow from the page.
/** @var $workflow \Drupal\workflow\Entity\Workflow */
if (!$workflow = workflow_url_get_workflow()) {
return ;
return [];
}
// The default min_weight is -10. Work with it.
@@ -320,7 +291,7 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
}
// Does user want to deactivate the state (reassign current content)?
if ($sid && $value['status'] == 0 && $state->isActive()) {
if ($state && $state->isActive() && !$value['status'] && $sid) {
$new_sid = $value['reassign'];
$new_state = WorkflowState::load($new_sid);
@@ -335,6 +306,11 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
$new_sid = NULL; // Do not reassign to new state.
$message = 'Removing workflow states from content in the %workflow.';
drupal_set_message($this->t($message, $args));
$message = 'Since you have deleted the last available
workflow state in this workflow, all content items
which with this %workflow workflow have their workflow state
removed.';
drupal_set_message($this->t($message, $args), 'warning');
}
else {
// Prepare the state delete function.
@@ -354,7 +330,7 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
$max_weight = max($max_weight, $state->get($this->weightKey));
// Is this a new state?
if ($sid == 'placeholder' && empty(!$value['label_new'])) {
if ($sid === 'placeholder' && empty(!$value['label_new'])) {
// New state, add it.
$state->set('id', $value['id']);
// Set a proper weight to the new state.
@@ -370,18 +346,42 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
$state->set('label', $value['label_new']);
$state->set('status', $value['status']);
$state->save();
try {
$state->save();
} catch(\Exception $e) {
$message = 'ID %id already exists';
$args = ['%id' => $state->id()];
return drupal_set_message($this->t($message, $args), 'error');
}
}
}
drupal_set_message(t('The Workflow states have been updated.'));
return;
if ($form_state->getTriggeringElement()['#name'] === 'add_state') {
// Unset previous input in placeholder and rebuild the form.
$input = $form_state->getUserInput();
unset($input['entities']['placeholder']['label_new']);
$form_state->setUserInput($input);
$form_state->setRebuild();
}
return drupal_set_message($this->t('The Workflow states have been updated.'));
}
/**
* Validate duplicate machine names. Function registered in 'machine_name'
* form element.
* 'Add State' button callback.
*
* @param array $form
* @param FormStateInterface $form_state
*
* @return
*/
public function addStateCallback(array &$form, FormStateInterface $form_state) {
return $form['entities'];
}
/**
* Validate duplicate machine names.
* Function registered in 'machine_name' form element.
*
* @param string $name
* @param array $element
@@ -402,5 +402,4 @@ class WorkflowStateListBuilder extends DraggableListBuilder {
}
return FALSE;
}
}
@@ -1,17 +1,14 @@
name: 'Workflow UI'
name: Workflow UI
type: module
description: 'Administrative UI for Workflow.'
package: Workflow
type: module
# core: 8.x
# version: VERSION
dependencies:
- workflow:workflow
configure: entity.workflow_type.collection
dependencies:
- workflow
# Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1+18-dev'
# Information added by Drupal.org packaging script on 2019-01-29
version: '8.x-1.1+35-dev'
core: '8.x'
project: 'workflow'
datestamp: 1536080308
datestamp: 1548801486
@@ -162,7 +162,7 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
}
else {
// Delete associated state (also deletes any associated transitions).
foreach ($this->getStates($all = TRUE) as $state) {
foreach ($this->getStates(TRUE) as $state) {
$state->deactivate('');
$state->delete();
}
@@ -179,7 +179,7 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
$is_valid = TRUE;
// Don't allow Workflow without states. There should always be a creation state.
$states = $this->getStates($all = FALSE);
$states = $this->getStates(FALSE);
if (count($states) < 1) {
// That's all, so let's remind them to create some states.
$message = t('Workflow %workflow has no states defined, so it cannot be assigned to content yet.',
@@ -211,7 +211,7 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
public function isDeletable() {
// May not be deleted if assigned to a Field.
foreach ($fields = _workflow_info_fields() as $field_info) {
foreach (_workflow_info_fields() as $field_info) {
if ($field_info->getSetting('workflow_type') == $this->id()) {
return FALSE;
}
@@ -238,7 +238,8 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
/* @var $state WorkflowState */
$state = WorkflowState::load($sid);
if (!$state || $wid != $state->getWorkflowId()) {
$state = WorkflowState::create($values = ['id' => $sid, 'wid' => $wid]);
$values = ['id' => $sid, 'wid' => $wid];
$state = WorkflowState::create($values);
if ($save) {
$state->save();
}
@@ -256,7 +257,7 @@ class Workflow extends ConfigEntityBase implements WorkflowInterface {
public function getCreationState() {
// First, find it.
if (!$this->creation_state) {
foreach ($this->getStates($all = TRUE) as $state) {
foreach ($this->getStates(TRUE) as $state) {
if ($state->isCreationState()) {
$this->creation_state = $state;
$this->creation_sid = $state->id();
@@ -151,7 +151,6 @@ class WorkflowConfigTransition extends ConfigEntityBase implements WorkflowConfi
public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
// Sort the entities using the entity class's sort() method.
// See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
/** @var WorkflowTransitionInterface $a */
/** @var WorkflowTransitionInterface $b */
if (!$a->getFromSid() || !$b->getFromSid()) {
@@ -139,14 +139,14 @@ class WorkflowManager implements WorkflowManagerInterface {
foreach (workflow_get_workflow_field_names($entity) as $field_name) {
// Transition is created in widget or WorkflowTransitionForm.
/** @var $transition WorkflowTransitionInterface */
$transition = $entity->$field_name->__get('workflow_transition');
$transition = $entity->{$field_name}->__get('workflow_transition');
if (!$transition) {
// We come from creating/editing an entity via entity_form, with core widget or hidden Workflow widget.
// @todo D8: from an Edit form with hidden widget.
/** @noinspection PhpUndefinedFieldInspection */
if ($entity->original) {
// Editing a Node with hidden Widget. State change not possible, so bail out.
// $entity->$field_name->value = $entity->original->$field_name->value;
// $entity->{$field_name}->value = $entity->original->{$field_name}->value;
// continue;
}
@@ -154,7 +154,7 @@ class WorkflowManager implements WorkflowManagerInterface {
// @todo D8: Test Creating a non-Node Entity with hidden Workflow widget.
$comment = '';
$old_sid = WorkflowManager::getPreviousStateId($entity, $field_name);
$new_sid = $entity->$field_name->value;
$new_sid = $entity->{$field_name}->value;
$field_info = FieldStorageConfig::loadByName($entity->getEntityTypeId(), $field_name);
if ((!$new_sid) && $wid = $field_info->getSetting('workflow_type')) {
/** @var Workflow $workflow */
@@ -170,7 +170,13 @@ class WorkflowManager implements WorkflowManagerInterface {
// but upon insert, the old version didn't have an ID, yet.
$transition->setTargetEntity($entity);
if ($transition->isScheduled()) {
if ($transition->isExecuted()) {
// Sometimes (due to Rules, or extra programming) it can happen that
// a Transition is executed twice in a call. This check avoids that
// situation, that generates message "Transition is executed twice".
$executed = TRUE;
}
elseif ($transition->isScheduled()) {
$executed = $transition->save(); // Returns a positive integer.
}
elseif ($entity->getEntityTypeId() == 'comment') {
@@ -284,19 +290,25 @@ class WorkflowManager implements WorkflowManagerInterface {
public static function cancelUser($edit, AccountInterface $account, $method) {
switch ($method) {
case 'user_cancel_block': // Disable the account and keep its content.
case 'user_cancel_block_unpublish': // Disable the account and unpublish its content.
case 'user_cancel_block':
// Disable the account and keep its content.
case 'user_cancel_block_unpublish':
// Disable the account and unpublish its content.
// Do nothing.
break;
case 'user_cancel_reassign': // Delete the account and make its content belong to the Anonymous user.
case 'user_cancel_delete': // Delete the account and its content.
// Update tables for deleted account, move account to user 0 (anon.)
// ALERT: This may cause previously non-Anonymous posts to suddenly
// be accessible to Anonymous.
case 'user_cancel_reassign':
// Delete the account and make its content belong to the Anonymous user.
case 'user_cancel_delete':
// Delete the account and its content.
/**
* Update tables for deleted account, move account to user 0 (anon.)
* ALERT: This may cause previously non-Anonymous posts to suddenly
* be accessible to Anonymous.
*/
/**
* Given a user id, re-assign history to the new user account. Called by user_delete().
* Given a user id, re-assign history to the new user account.
* Called by user_delete().
*/
$uid = $account->id();
$new_uid = 0;
@@ -386,13 +398,13 @@ class WorkflowManager implements WorkflowManagerInterface {
// If $field_name is not known, yet, determine it.
$field_name = ($field_name) ? $field_name : workflow_get_field_name($entity, $field_name);
// If $field_name is found, get more details.
if (!$field_name || !isset($entity->$field_name)) {
if (!$field_name || !isset($entity->{$field_name})) {
// Return the initial value.
return $sid;
}
// Normal situation: get the value.
$sid = $entity->$field_name->value;
$sid = $entity->{$field_name}->value;
// Entity is new or in preview or there is no current state. Use previous state.
// (E.g., content was created before adding workflow.)
@@ -78,7 +78,7 @@ class WorkflowScheduledTransition extends WorkflowTransition {
// this function is disabled for now.
// @todo: this function is only called in the WorkflowTransitionForm, not in the Widget.
// @todo: repair https://www.drupal.org/node/2896650
//
// The following is from return parent::validate();
$this->validated = TRUE;
//$violations = $this->getTypedData()->validate();
@@ -148,13 +148,6 @@ class WorkflowScheduledTransition extends WorkflowTransition {
return $result;
}
/**
* {@inheritdoc}
*/
// public static function loadMultiple(array $ids = NULL) {
// return parent::loadMultiple($ids);
// }
/**
* {@inheritdoc}
*/
@@ -207,7 +200,6 @@ class WorkflowScheduledTransition extends WorkflowTransition {
return $transitions;
}
/**
* Property functions.
*/
@@ -6,8 +6,8 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\Entity;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\workflow\WorkflowTypeAttributeTrait;
use Drupal\workflow\WorkflowURLRouteParametersTrait;
@@ -248,13 +248,12 @@ class WorkflowState extends ConfigEntityBase {
if ($new_sid) {
// A candidate for the batch API.
// @TODO: Future updates should seriously consider setting this with batch.
$user = \Drupal::currentUser(); // We can use global, since deactivate() is a UI-only function.
$comment = t('Previous state deleted');
foreach (_workflow_info_fields() as $field_info) {
$entity_type_id = $field_info->getTargetEntityTypeId();
$field_name = $field_info->getName(); // @todo: overwrites key?
$field_name = $field_info->getName();
$result = [];
// CommentForm's are not re-parented upon Deactivate WorkflowState.
@@ -458,7 +457,6 @@ class WorkflowState extends ConfigEntityBase {
// unset($transitions[$transition->id()]);
// }
// }
return $transitions;
}
@@ -542,7 +540,7 @@ class WorkflowState extends ConfigEntityBase {
$count = 0;
$sid = $this->id();
foreach ($fields = _workflow_info_fields() as $field_info) {
foreach (_workflow_info_fields() as $field_info) {
$field_name = $field_info->getName();
$query = \Drupal::entityQuery($field_info->getTargetEntityTypeId());
// @see #2285983 for using SQLite on D7.
@@ -73,35 +73,4 @@ class WorkflowStorage extends ConfigEntityStorage {
// return $events;
}
/**
* {@inheritdoc}
*/
public function doLoadMultiple(array $ids = NULL) {
$return = parent::doLoadMultiple($ids);
return $return;
}
/**
* {@inheritdoc}
*/
public function save(EntityInterface $entity) {
$return = parent::save($entity);
// // Update the state of registered events.
// // @todo Should we trigger a container rebuild here as well? Might be a bit
// // expensive on every save?
// $this->stateService->set('rules.registered_events', $this->getRegisteredEvents());
return $return;
}
/**
* {@inheritdoc}
*/
public function delete(array $entities) {
$return = parent::delete($entities);
return $return;
}
}
@@ -186,9 +186,7 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
* {@inheritdoc}
*/
public function save() {
// return parent::save();
// Set Target Entity to be used by Rules.
// Set Target Entity, to be used by Rules.
$reference = $this->get('entity_id')->first();
$reference->set('entity', $this->getTargetEntity());
@@ -215,12 +213,10 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
if ($this->isEmpty()) {
return SAVED_UPDATED;
}
// Update the transition, if already exists.
if ($this->id()) {
return parent::save();
}
// Insert the transition. Make sure it hasn't already been inserted.
// @todo: Allow a scheduled transition per revision.
// @todo: Allow a state per language version (langcode).
@@ -230,19 +226,9 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
$found_transition->getToSid() == $this->getToSid()) {
return SAVED_UPDATED;
}
else {
return parent::save();
}
return parent::save();
}
/**
* {@inheritdoc}
*/
// public static function loadMultiple(array $ids = NULL) {
// return parent::loadMultiple($ids);
// }
/**
* {@inheritdoc}
*/
@@ -329,7 +315,6 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
/**
* Check if anything has changed in this transition.
* @todo: check for attached fields.
*
* @return bool
*/
@@ -340,7 +325,14 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
if ($this->getComment()) {
return FALSE;
}
// @todo: check for attached fields.
$fields = WorkflowManager::getAttachedFields('workflow_transition', $this->bundle());
/** @var \Drupal\Core\Field\Entity\BaseFieldOverride $field */
foreach ($fields as $field_name => $field) {
if (!$this->{$field_name}->isEmpty()) {
return FALSE;
}
}
return true;
}
@@ -454,13 +446,11 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
}
$force = $this->isForced();
// @todo D8-port: figure out usage of $entity->workflow_transitions[$field_name]
/*
// Store the transition, so it can be easily fetched later on.
// Store in an array, to prepare for multiple workflow_fields per entity.
// This is a.o. used in hook_entity_update to trigger 'transition post'.
$entity->workflow_transitions[$field_name] = $this;
*/
// Store the transition(s), so it can be easily fetched later on.
// This is a.o. used in:
// - hook_entity_update to trigger 'transition post'.
// - hook workflow_access_node_access_records
$entity->workflow_transitions[$field_name] = $this;
if (!$this->isValid()) {
return $from_sid; // <-- exit !!!
@@ -506,7 +496,8 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
}
else {
// The transition is allowed, but not scheduled.
// Let other modules modify the comment. The transition (in context) contains all relevant data.
// Let other modules modify the comment.
// The transition (in context) contains all relevant data.
$context = ['transition' => $this];
\Drupal::moduleHandler()->alter('workflow_comment', $comment, $context);
$this->setComment($comment);
@@ -532,7 +523,7 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
// Notify modules that transition has occurred.
// Action triggers should take place in response to this callback, not the 'transaction pre'.
//
//\Drupal::moduleHandler()->invokeAll('workflow', ['transition post', $this, $user]);
// We have a problem here with Rules, Trigger, etc. when invoking
// 'transition post': the entity has not been saved, yet. we are still
@@ -595,8 +586,8 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
// N.B. Align the following functions:
// - WorkflowDefaultWidget::massageFormValues();
// - WorkflowManager::executeTransition().
$entity->$field_name->workflow_transition = $this;
$entity->$field_name->value = $this->getToSid();
$entity->{$field_name}->workflow_transition = $this;
$entity->{$field_name}->value = $this->getToSid();
$entity->save();
}
@@ -607,7 +598,6 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
public function post_execute($force = FALSE) {
// @todo D8-port: This function post_execute() is not yet used.
workflow_debug(__FILE__, __FUNCTION__, __LINE__); // @todo D8-port: Test this snippet.
if (!$this->isEmpty()) {
$user = $this->getOwner();
\Drupal::moduleHandler()->invokeAll('workflow', ['transition post', $this, $user]);
@@ -654,7 +644,7 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
return $this->entity;
}
// @todo D8: the following line only returns Node, not Term.
// return $this->entity = $this->get('entity_id')->entity;
/* return $this->entity = $this->get('entity_id')->entity; */
$entity_type = $this->getTargetEntityTypeId();
if ($id = $this->getTargetEntityId()) {
@@ -773,10 +763,10 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
* {@inheritdoc}
*/
public function schedule($schedule = TRUE) {
// // We do a tricky thing here. The id of the entity is altered, so
// // all functions of another subclass are called.
// $this->entityTypeId = ($schedule) ? 'workflow_scheduled_transition' : 'workflow_transition';
// We do a tricky thing here. The id of the entity is altered, so
// all functions of another subclass are called.
// $this->entityTypeId = ($schedule) ? 'workflow_scheduled_transition' : 'workflow_transition';
//
$this->is_scheduled = $schedule;
return $this;
}
@@ -28,7 +28,7 @@ class WorkflowTransitionForm extends ContentEntityForm {
// when multiple fields or entities are shown on 1 page.
// Test this f.i. by checking the'scheduled' box. It wil
// not unfold.
$form_id = parent::getFormId();
// $form_id = parent::getFormId();
/** @var $transition \Drupal\workflow\Entity\WorkflowTransitionInterface */
$transition = $this->entity;
@@ -122,7 +122,7 @@ class WorkflowTransitionForm extends ContentEntityForm {
$actions = parent::actions($form, $form_state);
// A default button is provided by core. Override it.
$actions['submit']['#value'] = t('Update workflow');
$actions['submit']['#value'] = $this->t('Update workflow');
$actions['submit']['#attributes'] = ['class' => ['form-save-default-button']];
if (!_workflow_use_action_buttons()) {
@@ -159,6 +159,7 @@ class WorkflowTransitionForm extends ContentEntityForm {
/**
* {@inheritdoc}
*/
/** @noinspection PhpMissingParentCallCommonInspection */
public function buildEntity(array $form, FormStateInterface $form_state) {
/** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */
$entity = clone $this->entity;
@@ -186,6 +187,7 @@ class WorkflowTransitionForm extends ContentEntityForm {
*
* This is called from submitForm().
*/
/** @noinspection PhpMissingParentCallCommonInspection */
public function save(array $form, FormStateInterface $form_state) {
// Execute transition and update the attached entity.
/** @var WorkflowTransitionInterface $transition */
@@ -15,15 +15,20 @@ class WorkflowTypeForm extends EntityForm {
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$noyes = [0 => t('No'), 1 => t('Yes')];
$fieldset_options = [0 => t('No fieldset'), 1 => t('Collapsible fieldset'), 2 => t('Collapsed fieldset')];
$fieldset_options = [
0 => $this->t('No fieldset'),
1 => $this->t('Collapsible fieldset'),
2 => $this->t('Collapsed fieldset')
];
/* @var $workflow Workflow */
$workflow = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#description' => t('The human-readable label of the workflow. This will be used as a label when
the workflow status is shown during editing of content.'),
'#description' => $this->t(
'The human-readable label of the workflow.This will be used as a label
when the workflow status is shown during editing of content.'
),
'#title' => $this->t('Label'),
'#default_value' => $this->entity->label(),
'#required' => TRUE,
@@ -31,68 +36,85 @@ class WorkflowTypeForm extends EntityForm {
$form['id'] = [
'#type' => 'machine_name',
'#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'),
'#description' => $this->t(
'A unique machine-readable name. Can only contain lowercase letters,
numbers, and underscores.'
),
'#disabled' => !$this->entity->isNew(),
'#default_value' => $this->entity->id(),
'#machine_name' => [
'exists' => [$this, 'exists'],
'replace_pattern' => '([^a-z0-9_]+)|(^custom$)',
'error' => $this->t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".'),
'error' => $this->t(
'The machine-readable name must be unique, and can only contain
lowercase letters, numbers, and underscores.
Additionally, it can not be the reserved word "custom".'
),
],
];
$form['permissions'] = [
'#type' => 'details',
'#title' => t('Workflow permissions'),
'#title' => $this->t('Workflow permissions'),
'#open' => TRUE, // Controls the HTML5 'open' attribute. Defaults to FALSE.
'#description' => t("To enable further Workflow functionality, go to the
/admin/people/permissions page and select any roles that should have
access to below and other functionalities."),
'#description' => $this->t(
'To enable further Workflow functionality, go to the
/admin/people/permissions page and select any roles that should
have access to below and other functionality.'),
];
$form['permissions']['transition_execute'] = [
'#type' => 'item',
'#title' => t('Participate in workflow (create, execute transitions)'),
'#markup' => t("You can determine which roles are enabled on the
'Workflow Transitions & roles' configuration page. Use this to enable
only the relevant roles. Some sites have too many roles to show on
the configuration page."),
'#title' => $this->t(
'Participate in workflow (create, execute transitions)'
),
'#markup' => $this->t(
"You can determine which roles are enabled on the
'Workflow Transitions & roles' configuration page. Use this to enable
only the relevant roles. Some sites have too many roles to show on
the configuration page."
),
];
$form['permissions']['transition_schedule'] = [
'#type' => 'item',
'#title' => t('Schedule state transition'),
'#markup' => t("Workflow transitions may be scheduled to a moment in the
future. Soon after the desired moment, the transition is executed by
Cron. This may be hidden by settings in widgets, formatters or permissions."
'#title' => $this->t('Schedule state transition'),
'#markup' => $this->t(
'Workflow transitions may be scheduled to a moment
in the future. Soon after the desired moment, the transition is
executed by Cron. This may be hidden by settings in widgets,
formatters or permissions.'
),
];
$form['permissions']['history_tab'] = [
'#type' => 'item',
'#title' => t('Access Workflow history tab'),
'#markup' => t("You can determine if a tab 'Workflow history' is
shown on the entity view page, which gives access to the History of
the workflow.
If you have multiple workflows per bundle, better disable this feature,
and use, clone & adapt the Views display 'Workflow history per Entity'."),
'#title' => $this->t('Access Workflow history tab'),
'#markup' => $this->t(
"You can determine if a tab 'Workflow history' is shown on the entity
view page, which gives access to the History of the workflow.
If you have multiple workflows per bundle, better disable this
feature, and use, clone & adapt the Views display
'Workflow history per Entity'."
),
];
$form['basic'] = [
'#type' => 'details',
'#title' => t('Workflow form settings'),
// '#description' => t('Lorem ipsum.'),
'#title' => $this->t('Workflow form settings'),
'#open' => TRUE, // Controls the HTML5 'open' attribute. Defaults to FALSE.
];
$form['basic']['fieldset'] = [
'#type' => 'select',
'#options' => $fieldset_options,
'#title' => t('Show the form in a fieldset?'),
'#default_value' => isset($workflow->options['fieldset']) ? $workflow->options['fieldset'] : 0,
'#title' => $this->t('Show the form in a fieldset?'),
'#default_value' => isset($workflow->options['fieldset'])
? $workflow->options['fieldset'] : 0,
];
$form['basic']['options'] = [
'#type' => 'select',
'#title' => t('How to show the available states'),
'#title' => $this->t('How to show the available states'),
'#required' => FALSE,
'#default_value' => isset($workflow->options['options']) ? $workflow->options['options'] : 'radios',
'#default_value' => isset($workflow->options['options'])
? $workflow->options['options'] : 'radios',
// '#multiple' => TRUE / FALSE,
'#options' => [
// These options are taken from options.module
@@ -101,28 +123,33 @@ class WorkflowTypeForm extends EntityForm {
'buttons' => 'Action buttons',
'dropbutton' => 'Drop button',
],
'#description' => t("The Widget shows all available states. Decide which
is the best way to show them."
'#description' => $this->t(
'The Widget shows all available states.
Decide which is the best way to show them.'
),
];
$form['basic']['name_as_title'] = [
'#type' => 'checkbox',
'#attributes' => ['class' => ['container-inline']],
'#title' => t('Use the workflow name as the title of the workflow form'),
'#default_value' => isset($workflow->options['name_as_title']) ? $workflow->options['name_as_title'] : 0,
'#description' => t(
'#title' => $this->t(
'Use the workflow name as the title of the workflow form'
),
'#default_value' => isset($workflow->options['name_as_title'])
? $workflow->options['name_as_title'] : 0,
'#description' => $this->t(
'The workflow section of the editing form is in its own fieldset.
Checking the box will add the workflow name as the title of workflow
section of the editing form.'
Checking the box will add the workflow name as the title of workflow
section of the editing form.'
),
];
$form['basic']['schedule_timezone'] = [
'#type' => 'checkbox',
'#title' => t('Show a timezone when scheduling a transition.'),
'#title' => $this->t('Show a timezone when scheduling a transition.'),
'#required' => FALSE,
'#default_value' => isset($workflow->options['schedule_timezone']) ? $workflow->options['schedule_timezone'] : 1,
'#default_value' => isset($workflow->options['schedule_timezone'])
? $workflow->options['schedule_timezone'] : 1,
];
$form['basic']['comment_log_node'] = [
@@ -130,30 +157,34 @@ class WorkflowTypeForm extends EntityForm {
'#required' => FALSE,
'#options' => [
// Use 0/1/2 to stay compatible with previous checkbox.
0 => t('hidden'),
1 => t('optional'),
2 => t('required'),
0 => $this->t('hidden'),
1 => $this->t('optional'),
2 => $this->t('required'),
],
'#attributes' => ['class' => ['container-inline']],
'#title' => t('How to show the Comment subfield'),
'#default_value' => isset($workflow->options['comment_log_node']) ? $workflow->options['comment_log_node'] : 1,
'#description' => t(
'A Comment area can be shown on the Workflow Transition form so that the person
making a state change can record reasons for doing so. The comment is
then included in the content\'s workflow history.'
'#title' => $this->t('How to show the Comment sub-field'),
'#default_value' => isset($workflow->options['comment_log_node'])
? $workflow->options['comment_log_node'] : 1,
'#description' => $this->t(
'A Comment area can be shown on the Workflow Transition form so that
the person making a state change can record reasons for doing so.
The comment is then included in the content\'s workflow history.'
),
];
$form['watchdog'] = [
'#type' => 'details',
'#title' => t('Watchdog'),
'#description' => t('Informational watchdog messages can be logged when a transition is executed (state of a node is changed).'),
'#title' => $this->t('Watchdog'),
'#description' => $this->t(
'Informational watchdog messages can be logged when a transition is
executed (state of a node is changed).'
),
'#open' => TRUE, // Controls the HTML5 'open' attribute. Defaults to FALSE.
];
$form['watchdog']['watchdog_log'] = [
'#type' => 'checkbox',
'#title' => t('Log watchdog messages upon state change'),
'#title' => $this->t('Log watchdog messages upon state change'),
'#default_value' => isset($workflow->options['watchdog_log']) ? $workflow->options['watchdog_log'] : 0,
'#description' => '',
];
@@ -197,9 +228,12 @@ class WorkflowTypeForm extends EntityForm {
$args = [
'%label' => $entity->label(),
'%action' => $action,
'link' => $entity->toLink(t('Edit'))->toString(),
'link' => $entity->toLink($this->t('Edit'))->toString(),
];
drupal_set_message($this->t('Workflow %label has been %action. Please maintain the permissions, states and transitions.', $args));
drupal_set_message($this->t(
'Workflow %label has been %action. Please maintain the permissions,
states and transitions.', $args)
);
$this->logger('workflow')->notice('Workflow %label has been %action.', $args);
if ($status == SAVED_NEW) {
@@ -30,7 +30,7 @@ class WorkflowDefaultWidget extends WidgetBase {
return [
/*
'workflow_default' => array(
'label' => t('Workflow'),
'label' => $this->t('Workflow'),
'field types' => array('workflow'),
'settings' => array(
'fieldset' => 0,
@@ -112,7 +112,7 @@ class WorkflowDefaultWidget extends WidgetBase {
// $form = $this->element($form, $form_state, $transition);
//$element['workflow_transition'] = array(
// '#type' => 'workflow_transition',
// '#title' => t('Workflow transition'),
// '#title' => $this->t('Workflow transition'),
// '#default_value' => $transition,
// );
@@ -170,7 +170,7 @@ class WorkflowDefaultWidget extends WidgetBase {
// Try to execute the transition. Return $from_sid when error.
if (!$transition) {
// This should not be possible (perhaps when testing/developing).
drupal_set_message(t('Error: the transition from %from_sid to %to_sid could not be generated.'), 'error');
drupal_set_message($this->t('Error: the transition from %from_sid to %to_sid could not be generated.'), 'error');
// The current value is still the previous state.
$to_sid = $from_sid = 0;
}
@@ -16,7 +16,10 @@ use Drupal\Core\Form\FormStateInterface;
* @todo: perhaps this is core functionality, but these values are only saved
* when the site builder explicitly save the instance settings. :-(
*/
function workflow_form_field_storage_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
function workflow_form_field_storage_config_edit_form_alter(&$form,
FormStateInterface $form_state,
/** @noinspection PhpUnusedParameterInspection */ $form_id) {
/** @noinspection PhpUndefinedMethodInspection */
$field_name = $form_state->getFormObject()->getEntity()->getType();
if ($field_name == 'workflow') {
@@ -32,7 +35,10 @@ function workflow_form_field_storage_config_edit_form_alter(&$form, FormStateInt
/**
* Implements hook_form_FORM_ID_alter().
*/
function workflow_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
function workflow_form_field_config_edit_form_alter(&$form,
FormStateInterface $form_state,
/** @noinspection PhpUnusedParameterInspection */ $form_id) {
/** @noinspection PhpUndefinedMethodInspection */
$field_name = $form_state->getFormObject()->getEntity()->getType();
if ($field_name == 'workflow') {
@@ -102,15 +108,15 @@ function workflow_state_formatter($entity, $field_name, $current_sid = '') {
}
// Clone the entity and restore old value, in case you want to show an
// executed transition.
if ($entity->$field_name->value != $current_sid) {
if ($entity->{$field_name}->value != $current_sid) {
$entity = clone $entity;
$entity->$field_name->value = $current_sid;
$entity->{$field_name}->value = $current_sid;
}
// Generate a renderable array for the field. Use default language determination ($langcode = NULL).
// First, add the 'current value' formatter for this field.
// $list_display = $instance['display']['default'];
$list_display['type'] = 'list_default';
$element = $entity->$field_name->view($list_display);
$element = $entity->{$field_name}->view($list_display);
// @todo D8: make weight better (even better: hook_field_extra_fields).
// Make sure the current value is before the form. (which has weight = 0.005)
@@ -121,7 +127,7 @@ function workflow_state_formatter($entity, $field_name, $current_sid = '') {
/**
* This function is a residue for installations that have v8.x-1.0
* The setting for options_allowed_values is still in the Field confuguration
* The setting for options_allowed_values is still in the Field configuration
* Saving the field data again does not remove the settings.
* So, we copy code from options_allowed_values().
*
@@ -1,17 +1,16 @@
name: 'Workflow'
name: Workflow
type: module
description: 'Defines a field type with Workflows, containing customizable state transitions.'
package: Workflow
type: module
# core: 8.x
# version: VERSION
dependencies:
- field
- options
- user
- drupal:field
- drupal:options
- drupal:user
# Information added by Drupal.org packaging script on 2018-09-04
version: '8.x-1.1+18-dev'
# Information added by Drupal.org packaging script on 2019-01-29
version: '8.x-1.1+35-dev'
core: '8.x'
project: 'workflow'
datestamp: 1536080308
datestamp: 1548801486
@@ -14,30 +14,40 @@ define('WORKFLOW_CREATION_STATE_NAME', 'creation');
/**
* Role ID for anonymous users.
*/
// #2657072 brackets are added later to indicate a special role, and distinguish from frequently used 'author' role.
// #2657072 brackets are added later to indicate a special role,
// and distinguish from frequently used 'author' role.
define('WORKFLOW_ROLE_AUTHOR_NAME', 'Author');
define('WORKFLOW_ROLE_AUTHOR_RID', 'workflow_author');
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\user\Entity\User;
use Drupal\workflow\Entity\Workflow;
use Drupal\workflow\Entity\WorkflowManager;
use Drupal\workflow\Entity\WorkflowScheduledTransition;
use Drupal\workflow\Entity\WorkflowState;
use Drupal\workflow\Entity\WorkflowTransition;
use Drupal\workflow\Entity\WorkflowTransitionInterface;
module_load_include('inc', 'workflow', 'workflow.form');
module_load_include('inc', 'workflow', 'workflow.field');
\Drupal::moduleHandler()->loadInclude('workflow', 'inc', 'workflow.form');
\Drupal::moduleHandler()->loadInclude('workflow', 'inc', 'workflow.field');
/**********************************************************************
*
* Info hooks.
*
*/
/**
* Implements hook_help().
*
* @param $route_name
* @param string $route_name
* A route.
*
* @return string
* The html output.
*/
function workflow_help($route_name) {
$output = '';
@@ -64,9 +74,7 @@ function workflow_hook_info() {
}
/**********************************************************************
*
* CRUD hooks.
*
*/
/**
@@ -76,21 +84,25 @@ function workflow_hook_info() {
* ALERT: This may cause previously non-Anonymous posts to suddenly
* be accessible to Anonymous.
*
* @see hook_user_cancel()
*
* @param $edit
* @param $account
* @param $method
* @param \Drupal\Core\Session\AccountInterface $account
* An account object.
* @param string $method
*
* @see hook_user_cancel()
*/
function workflow_user_cancel($edit, $account, $method) {
function workflow_user_cancel($edit, AccountInterface $account, $method) {
WorkflowManager::cancelUser($edit, $account, $method);
}
/**
* Implements hook_user_delete().
* @todo: hook_user_delete does not exist. hook_ENTITY_TYPE_delete?
*
* @param $account
* @param \Drupal\Core\Session\AccountInterface $account
* An account object.
*
* @todo: hook_user_delete does not exist. hook_ENTITY_TYPE_delete?
*/
function workflow_user_delete($account) {
WorkflowManager::deleteUser($account);
@@ -103,8 +115,9 @@ function workflow_user_delete($account) {
* The technical name for the Workflow entity is 'workflow_type'.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* An Entity.
*/
function workflow_workflow_type_insert(\Drupal\Core\Entity\EntityInterface $entity) {
function workflow_workflow_type_insert(EntityInterface $entity) {
WorkflowManager::participateUserRoles($entity);
}
@@ -112,19 +125,21 @@ function workflow_workflow_type_insert(\Drupal\Core\Entity\EntityInterface $enti
* Implements hook_entity_insert().
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* An Entity.
*/
function workflow_entity_insert(\Drupal\Core\Entity\EntityInterface $entity) {
function workflow_entity_insert(EntityInterface $entity) {
// Execute updates in hook_presave() to revert executions,
// Execute inserts in hook_insert, to have the Entity ID determined.
_workflow_execute_transitions($entity);
_workflow_execute_transitions($entity);
}
/**
* Implements hook_entity_presave().
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* An EntityInterface object.
*/
function workflow_entity_presave(\Drupal\Core\Entity\EntityInterface $entity) {
function workflow_entity_presave(EntityInterface $entity) {
if (!$entity->isNew()) {
// Avoid a double call by hook_entity_presave and hook_entity_insert.
_workflow_execute_transitions($entity);
@@ -132,14 +147,15 @@ function workflow_entity_presave(\Drupal\Core\Entity\EntityInterface $entity) {
}
/**
* Execute transitions. if prohibited, restore original field value.
* Execute transitions. if prohibited, restore original field value.
* - insert: use hook_insert(), to have the Entity ID determined when saving transitions.
* - update: use hook_presave() to revert executions,
* - so, do not use hook_update().
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* An Entity.
*/
function _workflow_execute_transitions(\Drupal\Core\Entity\EntityInterface $entity) {
function _workflow_execute_transitions(EntityInterface $entity) {
// Avoid this hook on workflow objects.
if (WorkflowManager::isWorkflowEntityType($entity->getEntityTypeId())) {
return;
@@ -155,9 +171,10 @@ function _workflow_execute_transitions(\Drupal\Core\Entity\EntityInterface $enti
* Delete the corresponding workflow table records.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* An Entity.
*/
function workflow_entity_delete(\Drupal\Core\Entity\EntityInterface $entity) {
// @todo D8: test with multiple workflows.
function workflow_entity_delete(EntityInterface $entity) {
// @todo: test with multiple workflows.
if (get_class($entity) == 'Drupal\field\Entity\FieldConfig'
|| get_class($entity) == 'Drupal\field\Entity\FieldStorageConfig') {
// A Workflow Field is removed from an entity.
@@ -204,14 +221,15 @@ function workflow_cron() {
*/
/**
* @deprecated D8: @see WorkflowManager::executeTransition().
*
* @param \Drupal\workflow\Entity\WorkflowTransitionInterface $transition
* A WorkflowTransition.
* @param bool $force
* Indicator if the transition must be forces.
*
* @return string
* A string.
*/
function workflow_execute_transition(Drupal\workflow\Entity\WorkflowTransitionInterface $transition, $force = FALSE) {
function workflow_execute_transition(WorkflowTransitionInterface $transition, $force = FALSE) {
// Execute transition and update the attached entity.
return $transition->executeAndUpdateEntity($force);
}
@@ -226,13 +244,13 @@ function workflow_execute_transition(Drupal\workflow\Entity\WorkflowTransitionIn
* - user_role
* - workflow
* - workflow_state
* - sid
* - sid.
*/
/**
* Retrieves the names of roles matching specified conditions.
*
* deprecated D8: workflow_get_roles --> workflow_get_user_role_names
* Deprecated D8: workflow_get_roles --> workflow_get_user_role_names.
*
* Usage:
* D7: $roles = workflow_get_user_role_names('participate in workflow');
@@ -284,7 +302,6 @@ function workflow_get_workflow_state_names($wid = '', $grouped = FALSE) {
// @see callback_allowed_values_function()
// @see options_allowed_values()
// Get the (user-dependent) options.
// Since this function is only used in UI, it is save to use the global $user.
$user = workflow_current_user();
@@ -316,6 +333,7 @@ function workflow_get_workflow_state_names($wid = '', $grouped = FALSE) {
*
* @param bool $required
* Indicates if the resulting list contains a options value.
*
* @return array
* An array of $wid => workflow->label().
*/
@@ -338,13 +356,19 @@ function workflow_get_workflow_names($required = TRUE) {
/**
* Gets an Options list of field names.
*
* @param null $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* An entity.
* @param string $entity_type
* An entity_type.
* @param string $entity_bundle
* An entity.
* @param string $field_name
* A field name.
*
* @return array
* An list of field names.
*/
function workflow_get_workflow_field_names($entity = NULL, $entity_type = '', $entity_bundle = '', $field_name = '') {
function workflow_get_workflow_field_names(EntityInterface $entity = NULL, $entity_type = '', $entity_bundle = '', $field_name = '') {
$result = [];
foreach (_workflow_info_fields($entity, $entity_type, $entity_bundle, $field_name) as $definition) {
$field_name2 = $definition->getName();
@@ -355,12 +379,13 @@ function workflow_get_workflow_field_names($entity = NULL, $entity_type = '', $e
/**
* Helper function, to get the label of a given State Id.
* deprecated: workflow_get_sid_label() --> workflow_get_sid_name()
*
* @param $sid
* @param string $sid
* A State ID.
*
* @return string
*
* deprecated: workflow_get_sid_label() --> workflow_get_sid_name()
* An translated label.
*/
function workflow_get_sid_name($sid) {
@@ -387,8 +412,9 @@ function workflow_get_sid_name($sid) {
* The field name. If given, will be passed as return value.
*
* @return string
* The found Field name.
*/
function workflow_get_field_name(\Drupal\Core\Entity\EntityInterface $entity, $field_name = '') {
function workflow_get_field_name(EntityInterface $entity, $field_name = '') {
if (!$entity) {
// $entity may be empty on Entity Add page.
return '';
@@ -411,23 +437,28 @@ function workflow_get_field_name(\Drupal\Core\Entity\EntityInterface $entity, $f
* We use UserInterface to check permissions.
*
* @param \Drupal\Core\Session\AccountInterface|null $account
* An Account.
*
* @return \Drupal\user\UserInterface
* A User.
*/
function workflow_current_user(\Drupal\Core\Session\AccountInterface $account = NULL) {
function workflow_current_user(AccountInterface $account = NULL) {
$account = ($account) ? $account : \Drupal::currentUser();
return \Drupal\user\Entity\User::load($account->id());
return User::load($account->id());
}
/**
* Gets the current state ID of a given entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* An entity.
* @param string $field_name
* A Field name.
*
* @return string $current_sid
* @return string
* The current State ID.
*/
function workflow_node_current_state(\Drupal\Core\Entity\EntityInterface $entity, $field_name = '') {
function workflow_node_current_state(EntityInterface $entity, $field_name = '') {
return WorkflowManager::getCurrentStateId($entity, $field_name);
}
@@ -435,28 +466,30 @@ function workflow_node_current_state(\Drupal\Core\Entity\EntityInterface $entity
* Gets the previous state ID of a given entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* An entity.
* @param string $field_name
* A field_name.
*
* @return string $previous_sid
* @return string
* The previous State ID.
*/
function workflow_node_previous_state(\Drupal\Core\Entity\EntityInterface $entity, $field_name = '') {
function workflow_node_previous_state(EntityInterface $entity, $field_name = '') {
return WorkflowManager::getPreviousStateId($entity, $field_name);
}
/**
* Get a specific workflow, given an entity type. Only one workflow is possible per node type.
* Get a specific workflow, given an entity type.
* Only one workflow is possible per node type.
* Caveat: gives undefined results with multiple workflows per entity.
* @todo: support multiple workflows per entity.
*
* @param string $entity_bundle
* An entity bundle.
* @param string $entity_type
* An entity type. This is passed when also the Field API must be checked.
*
* @return Workflow
* @return \Drupal\workflow\Entity\Workflow
* A Workflow object, or NULL if no workflow is retrieved.
*
* Caveat: gives undefined results with multiple workflows per entity.
*
* @todo: support multiple workflows per entity.
*/
function workflow_get_workflows_by_type($entity_bundle, $entity_type) {
static $map = [];
@@ -480,6 +513,13 @@ function workflow_get_workflows_by_type($entity_bundle, $entity_type) {
return $map[$entity_type][$entity_bundle];
}
/**
* Finds the Workflow fields on a given Entity type.
*
* @return mixed
*
* @see EntityFieldManager::getFieldMapByFieldType
*/
function workflow_get_workflow_fields_by_entity_type() {
return \Drupal::service('entity_field.manager')->getFieldMapByFieldType('workflow');
}
@@ -517,25 +557,26 @@ function _workflow_info_fields($entity = NULL, $entity_type = '', $entity_bundle
foreach ($data as $f_name => $value) {
if (!$entity_bundle || isset($value['bundles'][$entity_bundle])) {
if (!$field_name || ($field_name == $f_name)) {
// Do not use the field_name as ID, but the unique <entity_type>.<field_name>
// since you cannot share the same field on multiple entity_types (unlike D7).
$field_config = \Drupal\field\Entity\FieldStorageConfig::loadByName($e_type, $f_name);
// Do not use the field_name as ID, but the
// unique <entity_type>.<field_name> since you cannot share the
// same field on multiple entity_types (unlike D7).
$field_config = FieldStorageConfig::loadByName($e_type, $f_name);
if ($field_config) {
$field_info[$field_config->id()] = $field_config;
}
else {
// The field is a base/extra field not a configurable Field via Field UI.
// The field is a base/extra field.
// not a configurable Field via Field UI.
// Re-fetch the field definitions, with extra data.
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($e_type, $entity_bundle);
// @todo ?? Loop over bundles?
// @todo: ?? Loop over bundles?
/** @var \Drupal\Core\Field\BaseFieldDefinition $field_config */
$field_config = $field_definitions[$f_name];
if ($field_config) {
$field_info[$field_config->getUniqueStorageIdentifier()] = $field_config;
}
else {
// @todo ?? Loop over bundles?
// @todo: ?? Loop over bundles?
}
}
}
@@ -551,12 +592,15 @@ function _workflow_info_fields($entity = NULL, $entity_type = '', $entity_bundle
*
* This is a hack. It should be solved by using $route_match.
*
* @param \Drupal\Core\Entity\EntityInterface|null $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* An optional entity.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* A route.
*
* @return \Drupal\Core\Entity\EntityInterface
* Entity from the route.
*/
function workflow_url_get_entity(\Drupal\Core\Entity\EntityInterface $entity = NULL, \Drupal\Core\Routing\RouteMatchInterface $route_match = NULL) {
function workflow_url_get_entity(EntityInterface $entity = NULL, RouteMatchInterface $route_match = NULL) {
if ($entity) {
return $entity;
}
@@ -567,7 +611,7 @@ function workflow_url_get_entity(\Drupal\Core\Entity\EntityInterface $entity = N
$entities = [];
foreach ($route_match->getParameters() as $param) {
if ($param instanceof \Drupal\Core\Entity\EntityInterface) {
if ($param instanceof EntityInterface) {
$entities[] = $param;
}
}
@@ -581,7 +625,7 @@ function workflow_url_get_entity(\Drupal\Core\Entity\EntityInterface $entity = N
// On workflow tab, we'd get an id.
// This is an indicator that the route is mal-configured.
workflow_debug(__FILE__, __FUNCTION__, __LINE__, 'route declaration is not optimal.');
// return $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($value);
/* Return $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($value); */
return NULL;
}
@@ -593,7 +637,8 @@ function workflow_url_get_entity(\Drupal\Core\Entity\EntityInterface $entity = N
*
* For now only used for ../{entity_id}/workflow history tab.
*
* @return string|null $field_name
* @return string|null
* Return $field_name
*/
function workflow_url_get_field_name() {
return workflow_url_get_parameter('field_name');
@@ -603,9 +648,10 @@ function workflow_url_get_field_name() {
* Helper function to get the entity from a route.
*
* @return mixed|string
* Return $operation
*/
function workflow_url_get_operation() {
$url = \Drupal\Core\Url::fromRoute('<current>');
$url = Url::fromRoute('<current>');
// The last part of the path is the operation: edit, workflow, devel.
$url_parts = explode('/', $url->toString());
$operation = array_pop($url_parts);
@@ -619,30 +665,35 @@ function workflow_url_get_operation() {
/**
* Helper function to get arbitrary parameter from a route.
*
* @param $parameter
* @param string $parameter
* The requested parameter.
* @return string $field_name
*
* @return string
* field_name
*/
function workflow_url_get_parameter($parameter) {
return \Drupal::routeMatch()->getParameter($parameter);
// return \Drupal::request()->get($parameter);
// Return \Drupal::request()->get($parameter);
}
/**
* Helper function to determine Workflow from Workflow UI URL.
* @return Workflow
*
* @return \Drupal\workflow\Entity\Workflow
* Workflow Object.
*/
function workflow_url_get_workflow() {
/** @var $workflows \Drupal\workflow\Entity\Workflow[] */
static $workflows = [];
$wid = workflow_url_get_parameter('workflow_type');
if (is_object($wid)) { // $wid is a Workflow object.
if (is_object($wid)) {
// $wid is a Workflow object.
return $wid;
}
// $wid is a string
if (!isset($workflows[$wid])) {
// $wid is a string.
$workflows[$wid] = $wid ? Workflow::load($wid) : NULL;
}
return $workflows[$wid];
@@ -654,6 +705,7 @@ function workflow_url_get_workflow() {
* Used in file workflow_ui.routing.yml.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* the page title.
*/
function workflow_url_get_title() {
$label = '';
@@ -673,9 +725,12 @@ function workflow_url_get_title() {
* Helper function to determine Workflow from Workflow UI URL.
*
* @param string $url
* URL.
*
* @return mixed
* the Workflow type.
*/
function workflow_url_get_form_type($url = '' ) {
function workflow_url_get_form_type($url = '') {
// For some reason, $_SERVER is not allowed as default.
$url = ($url == '') ? $_SERVER['REQUEST_URI'] : $url;
@@ -687,18 +742,19 @@ function workflow_url_get_form_type($url = '' ) {
/**
* Helper function for D8-port: Get some info on screen.
* @see workflow_devel-module
*
* Usage:
* workflow_debug( __FILE__, __FUNCTION__, __LINE__, '', ''); // @todo D8-port: still test this snippet.
*
* @param string $class_name
* @param string $function_name
* @param string $line
* @param string $line_nr
* @param string $value1
* @param string $value2
*
* @see workflow_devel-module
*
* Usage:
* workflow_debug( __FILE__, __FUNCTION__, __LINE__, '', '');
*/
function workflow_debug($class_name, $function_name, $line = '', $value1 = '', $value2 = '') {
function workflow_debug($class_name, $function_name, $line_nr = '', $value1 = '', $value2 = '') {
$debug_switch = FALSE;
// $debug_switch = TRUE;
@@ -706,8 +762,8 @@ function workflow_debug($class_name, $function_name, $line = '', $value1 = '', $
return;
}
$class_name_elements = explode( "\\", $class_name);
$output = 'Testing... function ' . end($class_name_elements) . '::' . $function_name . '/' . $line;
$class_name_elements = explode("\\", $class_name);
$output = 'Testing... function ' . end($class_name_elements) . '::' . $function_name . '/' . $line_nr;
if ($value1) {
$output .= ' = ' . $value1;
}