Skip to content
Snippets Groups Projects

Draft: Issue #3456008 enum shape match

Closed Ted Bowman requested to merge issue/experience_builder-3456008:3456008-enum-match into 0.x
6 unresolved threads

Closes #3456008

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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 = [];
  • Ted Bowman added 1 commit

    added 1 commit

    • cd9a865b - ensure all indirect complex constraints from field item are found

    Compare with previous version

  • Wim Leers marked this merge request as ready

    marked this merge request as ready

  • Wim Leers marked this merge request as draft

    marked this merge request as draft

  • Accidentally marked the wrong draft MR as ready — sorry for the noise!

  • 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
  • 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();
  • 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', [
  • 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
  • closed

  • Please register or sign in to reply
    Loading