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

Issue #3507888: Enforce cardinality in field type definition/annotation

parent b264e4a1
No related branches found
No related tags found
No related merge requests found
Pipeline #429240 passed with warnings
......@@ -27,6 +27,7 @@ use Drupal\workflow\Entity\WorkflowTransitionInterface;
* constraints = {
* "WorkflowField" = {}
* },
* cardinality = 1,
* )
*/
class WorkflowItem extends ListItemBase {
......@@ -155,12 +156,6 @@ class WorkflowItem extends ListItemBase {
'#value' => $allowed_values_function,
];
$form['cardinality_container']['cardinality']['#default_value'] = 'number';
$form['cardinality_container']['cardinality']['#disabled'] = TRUE;
$form['cardinality_container']['cardinality_number']['#default_value'] = 1;
$form['cardinality_container']['cardinality_number']['#disabled'] = TRUE;
$form['cardinality_container']['cardinality_number']['#states'] = [];
return $element;
}
......
......@@ -155,7 +155,7 @@ class WorkflowDefaultWidget extends WidgetBase {
$user = workflow_current_user();
// Set the new value.
// Beware: We presume cardinality = 1 !!
// Beware: We presume WorkflowItem::cardinality = 1 !!
// The widget form element type has transformed the value to a
// WorkflowTransition object at this point. We need to convert it
// back to the regular 'value' string format.
......
......@@ -11,35 +11,6 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\workflow\Entity\WorkflowState;
/**
* Implements hook_form_FORM_ID_alter() for 'field_storage_config_edit_form'.
*
* Changes the hook_field_settings_form.
* Fixes some Field settings and Field Instance settings,
* and makes sure users cannot change it.
*
* @deprecated version 8.x-1.7, to be removed in 8.x-2.0
* @see https://www.drupal.org/project/workflow/issues/3425370
*/
function workflow_form_field_storage_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (version_compare(\Drupal::VERSION, '10.2', '>=')) {
// This is now done in WorkflowItem::storageSettingsForm
// And in workflow_form_field_config_edit_form_alter.
}
else {
$field_type = $form_state->getFormObject()->getEntity()->getType();
if ($field_type == 'workflow') {
// Make sure only 1 value can be entered in the Workflow field.
$form['cardinality_container']['cardinality']['#default_value'] = 'number';
$form['cardinality_container']['cardinality']['#disabled'] = TRUE;
$form['cardinality_container']['cardinality_number']['#default_value'] = 1;
$form['cardinality_container']['cardinality_number']['#disabled'] = TRUE;
$form['cardinality_container']['cardinality_number']['#states'] = [];
}
}
}
/**
* Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment