Skip to content
Snippets Groups Projects
Commit 0f2cf30f authored by John Voskuilen's avatar John Voskuilen
Browse files

Issue #3513418 by dcoppel, arunsahijpal, spiderman: WidgetBase::errorElement()...

Issue #3513418 by dcoppel, arunsahijpal, spiderman: WidgetBase::errorElement() - exception needed for radio buttons; better defaultvalue
parent 3e7ec28b
No related branches found
No related tags found
No related merge requests found
Pipeline #455268 passed with warnings
......@@ -167,7 +167,7 @@ class WorkflowTransitionElement extends FormElement {
$widget = workflow_state_formatter($entity, $field_name, $from_sid);
$widget['#access'] = TRUE;
}
$element['from_sid'] = $widget;
$element[$attribute_name] = $widget;
// Add the 'options' widget.
// It may be replaced later if 'Action buttons' are chosen.
......@@ -182,12 +182,9 @@ class WorkflowTransitionElement extends FormElement {
'#description' => $help_text,
// When not $show_widget, the 'from_sid' is displayed.
'#access' => $show_widget,
// '#default_value' => $default_value,
// @todo This is only needed for 'radios'. Why?
'#default_value' => $a = reset($element[$attribute_name][$attribute_key]['#default_value']),
];
// @todo Do not set options in any case.
// if ($options) {
// $widget['#options'] = $options;
// }
// Subfield is NEVER disabled in Workflow 'Manage form display' settings.
// @see addPreSaveBasefieldWarning()
self::updateWidget($element[$attribute_name], $attribute_key, $widget);
......
......@@ -826,10 +826,41 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
/**
* {@inheritdoc}
*/
public static function getDefaultRequestTime() {
public static function getDefaultRequestTime(WorkflowTransition $transition, BaseFieldDefinition $definition) {
return \Drupal::time()->getRequestTime();
}
/**
* {@inheritdoc}
*
* @see workflow_node_current_state
*/
public static function getDefaultStateId(WorkflowTransition $transition, BaseFieldDefinition $definition) {
$sid = '';
switch ($definition->getName()) {
case 'from_sid':
// Not implemented yet, since from_sid is given upon creation.
break;
case 'to_sid':
$current_state = $transition->getFromState();
$sid = $current_state->id();
if ($current_state->isCreationState()) {
$sid = $current_state->getWorkflow()->getFirstSid(
$transition,
$transition->getFieldName(),
$transition->getOwner());
}
break;
default:
// Error. Should not happen.
break;
}
return $sid;
}
/**
* {@inheritdoc}
*/
......@@ -1026,8 +1057,11 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
$fields['from_sid'] = BaseFieldDefinition::create('list_string')
->setLabel(t('From state'))
->setDescription(t('The {workflow_states}.sid the entity started as.'))
->setCardinality(1)
// Do not change. @see https://www.drupal.org/project/drupal/issues/2643308
->setSetting('allowed_values_function', 'workflow_state_allowed_values')
->setDefaultValueCallback(static::class . '::getDefaultStateId')
->setRequired(TRUE)
->setDisplayOptions('form', [
'type' => 'options_select',
......@@ -1038,9 +1072,10 @@ class WorkflowTransition extends ContentEntityBase implements WorkflowTransition
$fields['to_sid'] = BaseFieldDefinition::create('list_string')
->setLabel(t('To state'))
->setDescription(t('The {workflow_states}.sid the entity transitioned to.'))
->setCardinality(1)
// Do not change. @see https://www.drupal.org/project/drupal/issues/2643308
->setSetting('allowed_values_function', 'workflow_state_allowed_values')
// @todo ->setDefaultValueCallback('workflow_node_current_state')
->setDefaultValueCallback(static::class . '::getDefaultStateId')
->setRequired(TRUE)
->setDisplayOptions('form', [
'type' => 'options_select',
......
......@@ -283,6 +283,7 @@ class WorkflowItem extends ListItemBase {
return $transition;
}
// @todo Move to WorkflowTransition::getDefaultStateId().
// Create a transition, to pass to the form.
$user = workflow_current_user();
$entity = $this->getEntity();
......@@ -295,16 +296,8 @@ class WorkflowItem extends ListItemBase {
return $transition;
}
// getDefaultToSid().
$new_sid = $current_sid;
$current_state = WorkflowState::load($current_sid);
if ($current_state->isCreationState()) {
$new_sid = $current_state->getWorkflow()->getFirstSid($entity, $field_name, $user);
}
$transition = WorkflowTransition::create([$current_sid, 'field_name' => $field_name])
->setTargetEntity($entity)
->setValues($new_sid);
->setTargetEntity($entity);
return $transition;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment