updated i18n i10n_update workflwo imachecache_actions

This commit is contained in:
2020-06-23 12:41:21 +02:00
parent 8c39ab6f4a
commit 092758ecb0
134 changed files with 2894 additions and 1205 deletions
@@ -89,7 +89,7 @@ class Workflow extends Entity implements WorkflowInterface {
protected function preRebuild() {
// Remap roles. They can come from another system with shifted role IDs.
// See also https://drupal.org/node/1702626 .
$this->rebuildRoles($this->tab_roles);
$this->tab_roles = $this->rebuildRoles($this->tab_roles);
// After update.php or import feature, label might be empty. @todo: remove in D8.
if (empty($this->label)) {
@@ -160,30 +160,32 @@ class Workflow extends Entity implements WorkflowInterface {
$data = (array)$data;
if (is_numeric($name)) {
$start_state = $saved_states[$saved_state_names[$data['sid']]];
$end_state = $saved_states[$saved_state_names[$data['target_sid']]];
$name = WorkflowConfigTransition::machineName($start_state->getName(),
$end_state->getName());
if (isset($saved_states[$data['sid']]) && isset($saved_states[$data['target_sid']])) {
$start_state = $saved_states[$data['sid']]; // #2876303
$end_state = $saved_states[$data['target_sid']]; // #2876303
}
else {
$start_state = $this->getState($data['sid']);
$end_state = $this->getState($data['target_sid']);
}
}
else {
$start_state = $saved_states[$data['start_state']];
$end_state = $saved_states[$data['end_state']];
}
$name = WorkflowConfigTransition::machineName($start_state->getName(), $end_state->getName());
if (isset($db_transitions[$name])) {
$transition = $db_transitions[$name];
}
else {
$transition = $this->createTransition($start_state->sid,
$end_state->sid);
$transition = $this->createTransition($start_state->sid, $end_state->sid);
}
$transition->wid = $this->wid;
$transition->sid = $start_state->sid;
$transition->target_sid = $end_state->sid;
$transition->label = $data['label'];
$transition->roles = $data['roles'];
$this->rebuildRoles($transition->roles);
$transition->roles = $this->rebuildRoles($data['roles']);
$transition->save();
unset($db_transitions[$name]);
@@ -251,12 +253,14 @@ class Workflow extends Entity implements WorkflowInterface {
public function isValid() {
$is_valid = TRUE;
$workflow_name = $this->getName();
$wid = $this->getWorkflowId();
// Don't allow workflows with no states. There should always be a creation state.
$states = $this->getStates($all = 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.',
array('%workflow' => $this->getName()));
array('%workflow' => $workflow_name));
drupal_set_message($message, 'warning');
// Skip allowing this workflow.
@@ -268,7 +272,7 @@ class Workflow extends Entity implements WorkflowInterface {
if (count($transitions) < 1) {
// That's all, so let's remind them to create some transitions.
$message = t('Workflow %workflow has no transitions defined, so it cannot be assigned to content yet.',
array('%workflow' => $this->getName()));
array('%workflow' => $workflow_name));
drupal_set_message($message, 'warning');
// Skip allowing this workflow.
@@ -281,7 +285,7 @@ class Workflow extends Entity implements WorkflowInterface {
$message = t('Please maintain Workflow %workflow on its <a href="@url">settings</a> page.',
array(
'%workflow' => $this->getName(),
'@url' => url('admin/config/workflow/workflow/manage/' . $this->wid),
'@url' => url(WORKFLOW_ADMIN_UI_PATH . "/manage/$wid"),
)
);
drupal_set_message($message, 'warning');
@@ -539,19 +543,7 @@ class Workflow extends Entity implements WorkflowInterface {
}
/**
* Loads all allowed ConfigTransitions for this workflow.
*
* @param mixed $tids
* Array of Transitions IDs. If FALSE, show all transitions.
* @param array $conditions
* $conditions['sid'] : if provided, a 'from' State ID.
* $conditions['target_sid'] : if provided, a 'to' state ID.
* $conditions['roles'] : if provided, an array of roles, or 'ALL'.
* @param bool $reset
* Indicator to reset the cache.
*
* @return array
* An array of keyed transitions.
* @inheritdoc
*/
public function getTransitions($tids = FALSE, array $conditions = array(), $reset = FALSE) {
$config_transitions = array();
@@ -690,21 +682,22 @@ class Workflow extends Entity implements WorkflowInterface {
}
protected function defaultLabel() {
return isset($this->label) ? $this->label : '';
return isset($this->label) ? t('@label', array('@label' => $this->label)) : '';
}
protected function defaultUri() {
return array('path' => 'admin/config/workflow/workflow/manage/' . $this->wid);
$wid = $this->wid;
return array('path' => WORKFLOW_ADMIN_UI_PATH . "/manage/$wid");
}
protected function rebuildRoles(array &$roles) {
$role_map = isset($this->system_roles) ? $this->system_roles : array();
if (!$role_map) {
return;
}
protected function rebuildRoles(array $roles) {
$new_roles = array();
// @todo: importing Roles is incomplete when user language is not English.
// function user_roles() translates DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID
$role_map = workflow_get_roles(NULL);
// See also https://drupal.org/node/1702626 .
$new_roles = array();
foreach ($roles as $key => $rid) {
if ($rid == WORKFLOW_ROLE_AUTHOR_RID) {
$new_roles[$rid] = $rid;
@@ -715,7 +708,7 @@ class Workflow extends Entity implements WorkflowInterface {
}
}
}
$roles = $new_roles;
return $new_roles;
}
}
@@ -51,11 +51,12 @@ class WorkflowConfigTransition extends Entity {
}
protected function defaultLabel() {
return $this->label;
return isset($this->label) ? t('@label', array('@label' => $this->label)) : '';
}
protected function defaultUri() {
return array('path' => 'admin/config/workflow/workflow/manage/' . $this->wid . '/transitions/');
$wid = $this->wid;
return array('path' => WORKFLOW_ADMIN_UI_PATH . "/manage/$wid/transitions/");
}
/**
@@ -96,11 +97,16 @@ class WorkflowConfigTransition extends Entity {
* - In permissions;
* - By permission hooks, implemented by other modules.
*
* @param string|array $user_roles
* The string 'ALL' to force allowing the transition, or an array of role
* IDs to compare against the roles allowed for the transition.
*
* @return bool
* TRUE if OK, else FALSE.
* If the transition is allowed, this function returns TRUE. Otherwise, it
* returns FALSE.
*/
public function isAllowed($user_roles) {
if ($user_roles == 'ALL') {
if ($user_roles === 'ALL') {
// Superuser.
return TRUE;
}
@@ -132,6 +138,25 @@ class WorkflowConfigTransition extends Entity {
$workflow->save();
}
}
/**
* Helper debugging function to easily show the contents of a transition.
*/
public function dpm($function = 'not_specified') {
$transition = $this;
$time = NULL;
// Do this extensive $user_name lines, for some troubles with Action.
$t_string = get_class($this) . ' ' . $this->identifier() . " in function '$function'";
//$output[] = 'Entity = ' . ((!$entity) ? 'NULL' : ($entity_type . '/' . $entity_bundle . '/' . $entity_id));
//$output[] = 'Field = ' . $transition->getFieldName();
$output[] = 'From/To = ' . $transition->sid . ' > ' . $transition->target_sid . ' @ ' . $time;
//$output[] = 'Comment = ' . $user_name . ' says: ' . $transition->getComment();
//$output[] = 'Forced = ' . ($transition->isForced() ? 'yes' : 'no');
if (function_exists('dpm')) { dpm($output, $t_string); }
}
}
/**
@@ -154,11 +154,14 @@ interface WorkflowInterface {
/**
* Loads all allowed ConfigTransitions for this workflow.
*
* @param array|NULL $ids
* Array of Transitions IDs. If NULL, show all transitions.
* @param array|bool $tids
* Array of Transitions IDs. If FALSE, show all transitions.
* @param array $conditions
* $conditions['from_sid'] : if provided, a 'from' State ID.
* $conditions['to_sid'] : if provided, a 'to' state ID.
* $conditions['sid'] : if provided, a 'from' State ID.
* $conditions['target_sid'] : if provided, a 'to' state ID.
* $conditions['roles'] : if provided, an array of roles, or 'ALL'.
* @param bool $reset
* Indicator to reset the cache.
*
* @return \Drupal\workflow\Entity\WorkflowConfigTransition[]
*/
@@ -153,7 +153,7 @@ class WorkflowState extends Entity {
public static function loadByName($name, $wid = 0) {
/* @var $state WorkflowState */
foreach ($states = self::getStates($wid) as $state) {
if ($name == $state->getName()) {
if ($name == $state->name) {
return $state;
}
}
@@ -458,7 +458,7 @@ class WorkflowState extends Entity {
// We cannot use getTransitions, since there are no ConfigTransitions
// from State with ID 0, and we do not want to repeat States.
foreach ($workflow->getStates() as $state) {
$options[$state->value()] = $state->label(); // Translation is done later.
$options[$state->value()] = $state->label(); // Translation is done as part of defaultLabel().
}
}
else {
@@ -473,7 +473,7 @@ class WorkflowState extends Entity {
$label = $target_state ? $target_state->label() : '';
}
$new_sid = $transition->target_sid;
$options[$new_sid] = $label; // Translation is done later.
$options[$new_sid] = $label; // Translation is done as part of defaultLabel().
}
// Include current state for same-state transitions, except when $sid = 0.
@@ -481,16 +481,10 @@ class WorkflowState extends Entity {
// but only if the transitions have been saved at least one time.
if ($current_sid && ($current_sid != $workflow->getCreationSid())) {
if (!isset($options[$current_sid])) {
$options[$current_sid] = $this->label(); // Translation is done later.
$options[$current_sid] = $this->label(); // Translation is done as part of defaultLabel().
}
}
// Properly fix the labels.
// Translate, convert '&', make secure.
foreach($options as $key => $label) {
$options[$key] = html_entity_decode(check_plain(t($label)));
}
// Save to entity-specific cache.
$cache[$entity_type][$entity_index][$force][$current_sid] = $options;
}
@@ -538,7 +532,7 @@ class WorkflowState extends Entity {
* Mimics Entity API functions.
*/
protected function defaultLabel() {
return $this->state;
return isset($this->state) ? t('@state', array('@state' => $this->state)) : '';
}
public function getName() {
@@ -446,7 +446,7 @@ class WorkflowTransition extends Entity {
$args = array(
'@type' => $entity_type_info['label'],
'%label' => entity_label($entity_type, $entity),
'%state_name' => check_plain(t($new_state->label())),
'%state_name' => $new_state->label(),
);
$uri = entity_uri($entity_type, $entity);
watchdog('workflow', $message, $args, WATCHDOG_NOTICE, l('view', $uri['path']));
@@ -111,7 +111,7 @@ class WorkflowItem extends WorkflowD7Base {// D8: extends ConfigFieldItemBase im
'#default_value' => $wid,
'#required' => TRUE,
'#disabled' => $has_data,
'#description' => t('Choose the Workflow type. Maintain workflows !url.', array('!url' => l(t('here'), 'admin/config/workflow/workflow'))),
'#description' => t('Choose the Workflow type. Maintain workflows !url.', array('!url' => l(t('here'), WORKFLOW_ADMIN_UI_PATH))),
);
// Inform the user of possible states.
@@ -297,7 +297,7 @@ class WorkflowItem extends WorkflowD7Base {// D8: extends ConfigFieldItemBase im
$previous_wid = $state->wid;
$lines[] = $state->name . "'s states: ";
}
$label = check_plain(t($state->label()));
$label = $state->label();
$states[$state->sid] = $label;
$lines[] = $state->sid . ' | ' . $label;
}
@@ -317,12 +317,13 @@ class WorkflowItem extends WorkflowD7Base {// D8: extends ConfigFieldItemBase im
* @return array
* The array of allowed values. Keys of the array are the raw stored values
* (number or text), values of the array are the display labels.
* It contains all possible values, beause the result is cached,
* and used for all nodes on a page.
* It contains all possible values for the field, because the result is
* cached on a field basis, and used for all nodes on a page.
*/
public function getAllowedValues() {
// Get all state names, including inactive states.
$options = workflow_get_workflow_state_names(0, $grouped = FALSE, $all = TRUE);
$wid = isset($this->field['settings']['wid']) ? $this->field['settings']['wid'] : 0;
$options = workflow_get_workflow_state_names($wid, $grouped = FALSE, $all = TRUE);
return $options;
}
@@ -190,7 +190,7 @@ class WorkflowTransitionForm { // extends FormBase {
}
}
$workflow_label = $workflow ? check_plain(t($workflow->label())) : '';
$workflow_label = $workflow ? $workflow->label() : '';
// Change settings locally.
if (!$field_name) {
@@ -300,7 +300,7 @@ class WorkflowTransitionForm { // extends FormBase {
else {
$element['workflow'] += array(
'#type' => 'fieldset',
'#title' => t($workflow_label),
'#title' => $workflow_label,
'#collapsible' => TRUE,
'#collapsed' => ($settings_fieldset == 1) ? FALSE : TRUE,
);
@@ -312,13 +312,13 @@ class WorkflowTransitionForm { // extends FormBase {
$help_text = isset($instance['description']) ? $instance['description'] : '';
$element['workflow']['workflow_sid'] = array(
'#type' => $settings_options_type,
'#title' => $settings_title_as_name ? t('Change !name state', array('!name' => $workflow_label)) : t('Target state'),
'#title' => $settings_title_as_name ? t('Change @name state', array('@name' => $workflow_label)) : t('Target state'),
'#access' => TRUE,
'#options' => $options,
// '#name' => $workflow_label,
// '#parents' => array('workflow'),
'#default_value' => $default_value,
'#description' => $help_text,
'#description' => t('@help', array('@help' => $help_text)),
);
}
@@ -605,7 +605,7 @@ class WorkflowTransitionForm { // extends FormBase {
// content is not associated to a workflow, old_sid is now 0. This may
// happen in workflow_vbo, if you assign a state to non-relevant nodes.
$entity_id = entity_id($entity_type, $entity);
drupal_set_message(t('Error: content !id has no workflow attached. The data is not saved.', array('!id' => $entity_id)), 'error');
drupal_set_message(t('Error: content @id has no workflow attached. The data is not saved.', array('@id' => $entity_id)), 'error');
// The new state is still the previous state.
$new_sid = $old_sid;
return $new_sid;
@@ -617,7 +617,8 @@ class WorkflowTransitionForm { // extends FormBase {
// Try to execute the transition. Return $old_sid when error.
if (!$transition) {
// This should only happen when testing/developing.
drupal_set_message(t('Error: the transition from %old_sid to %new_sid could not be generated.'), 'error');
drupal_set_message(t('Error: the transition from @old_sid to @new_sid could not be generated.',
array('@old_sid' => $old_sid, '@new_sid' => $new_sid)), 'error');
// The current value is still the previous state.
$new_sid = $old_sid;
}