Issue #1266748 by swentel, Berdir, jcnventura, arlinsandbulte, yched, droplet,...
Issue #1266748 by swentel, Berdir, jcnventura, arlinsandbulte, yched, droplet, amateescu: Changing cardinality lower than highest existing delta causes data loss upon save
$form_state->setErrorByName('cardinality_number',$this->formatPlural($entities_with_higher_delta,'There is @count entity with @delta or more values in this field.','There are @count entities with @delta or more values in this field.',['@delta'=>$form_state->getValue('cardinality')+1]));
// Assert that you can't set the cardinality to a lower number than the
// highest delta of this field.
$edit=[
'cardinality'=>'number',
'cardinality_number'=>1,
];
$this->drupalPostForm($field_edit_path,$edit,t('Save field settings'));
$this->assertRaw(t('There is @count entity with @delta or more values in this field.',['@count'=>1,'@delta'=>2]),'Correctly failed to set cardinality lower than highest delta.');
// Assert that you can't set the cardinality to a lower number then the
// highest delta of this field but can set it to the same.
$edit=[
'cardinality'=>'number',
'cardinality_number'=>1,
];
$this->drupalPostForm($field_edit_path,$edit,t('Save field settings'));
$this->assertRaw(t('There are @count entities with @delta or more values in this field.',['@count'=>2,'@delta'=>2]),'Correctly failed to set cardinality lower than highest delta.');
$edit=[
'cardinality'=>'number',
'cardinality_number'=>2,
];
$this->drupalPostForm($field_edit_path,$edit,t('Save field settings'));
$this->assertRaw(t('There is @count entity with @delta or more values in this field.',['@count'=>1,'@delta'=>3]),'Correctly failed to set cardinality lower than highest delta.');
$edit=[
'cardinality'=>'number',
'cardinality_number'=>3,
];
$this->drupalPostForm($field_edit_path,$edit,t('Save field settings'));