Draft: Issue #3456008 enum shape match
6 unresolved threads
6 unresolved threads
Closes #3456008
Merge request reports
Activity
Filter activity
623 628 else { 624 629 $field_item_level_constraints_indirect = []; 625 630 } 631 if (!array_is_list($field_item->getConstraints())) { 632 throw new \Exception("I don't think this ever happens??, so line below will never have match"); 633 } 626 634 $field_item_level_constraints_direct = $field_item->getConstraints()[$field_property_name] ?? []; 635 // Just reset to confirm there is no test that actually tests this. 636 $field_item_level_constraints_direct = []; - Comment on lines +631 to +636
changed this line in version 3 of the diff
added 1 commit
- cd9a865b - ensure all indirect complex constraints from field item are found
637 foreach ($field_item_constraints as $field_item_constraint) { 638 if ($field_item_constraint instanceof ComplexDataConstraint) { 639 if (isset($field_item_constraint->properties[$field_property_name])) { 640 $field_item_level_constraints_indirect += $rekey($field_item_constraint->properties[$field_property_name]); 641 } 642 } 643 } 644 if (!array_is_list($field_item->getConstraints()) || isset($field_item->getConstraints()[$field_property_name])) { 645 throw new \Exception("I don't think this ever happens??, so line below will never have match"); 646 } 647 $field_item_level_constraints_direct = $field_item->getConstraints()[$field_property_name] ?? []; 648 // Just reset to confirm there is no test that actually tests this. 649 $field_item_level_constraints_direct = []; 650 651 // $field_item_level_constraints_indirect has already has $rekey() applied. 652 $constraints = $field_item_level_constraints_indirect 613 618 // Gather all constraints that apply to this field item property. 614 619 $property_level_constraints = $data->getConstraints(); 615 $complex_data_constraint = array_filter( 616 $field_item->getConstraints(), 617 fn ($c) => $c instanceof ComplexDataConstraint 618 ); 619 if (!empty($complex_data_constraint)) { 620 $field_item_level_constraints_indirect = reset($complex_data_constraint) 621 ->properties[$field_property_name] ?? []; 622 } 623 else { 624 $field_item_level_constraints_indirect = []; 625 } 626 $field_item_level_constraints_direct = $field_item->getConstraints()[$field_property_name] ?? []; 620 $field_item_constraints = $field_item->getConstraints(); 621 $field_item_level_constraints_indirect = []; 610 610 assert($field_item instanceof FieldItemInterface); 611 611 $field_property_name = $data->getName(); 612 612 613 // @todo Not sure how list_string is suppose to work with the following code 614 // 1. \Drupal\Core\Validation\Plugin\Validation\Constraint\AllowedValuesConstraint doe not extend ComplexDataConstraint 615 // 2. \Drupal\Core\TypedData\TypedDataManager::getDefaultConstraints `$constraints['AllowedValues'] = [];` so with no options for the choices 616 // 3. $field_item->getConstraints() returns the an array with 1 item key=0 and value=AllowedValuesConstraint 617 // 4. so the constraint will never be in $field_item_level_constraints_indirect or $field_item_level_constraints_direct - Comment on lines +613 to +617
This will partially still be relevant for https://www.drupal.org/project/experience_builder/issues/3456008#comment-15784039.
103 103 'required' => TRUE, 104 104 ])->save(); 105 FieldStorageConfig::create([ 106 'field_name' => 'field_string_option', 107 'entity_type' => 'node', 108 'type' => 'list_string', 109 'settings' => [ 110 'allowed_values' => ['foo' => 'Foo Option', 'bar' => 'Bar option'], 111 ], 112 ])->save(); 113 FieldConfig::create([ 114 'entity_type' => 'node', 115 'field_name' => 'field_string_option', 116 'bundle' => 'foo', 117 'required' => TRUE, 118 ])->save(); - Comment on lines +105 to +118
This will still be relevant when implementing https://www.drupal.org/project/experience_builder/issues/3456008#comment-15784039.
91 91 // - `pattern`: https://json-schema.org/understanding-json-schema/reference/string#regexp 92 92 // - `format`: https://json-schema.org/understanding-json-schema/reference/string#format and https://json-schema.org/understanding-json-schema/reference/string#built-in-formats 93 93 SdcPropJsonSchemaType::STRING => match (TRUE) { 94 array_key_exists('enum', $schema) => new DataTypeShapeRequirement('Choice', [ 94 array_key_exists('enum', $schema) => new DataTypeShapeRequirement('AllowedValues', [ - Comment on lines -94 to +94
This might be relevant when working on https://www.drupal.org/project/experience_builder/issues/3456008#comment-15784039
Because >50% of this MR won't be relevant anymore when https://www.drupal.org/project/experience_builder/issues/3456008#comment-15784039 gets worked on eventually, so closing this MR.
Edited by Wim Leers
Please register or sign in to reply