Introduce "adapters"
Goals
- Being able to write adaptors that can perform BE logic and adapt Drupal field values to match props
Non-goals
- Good UX
- Any UI to change the expression used for a
sourceType == dynamic
prop value - Nested adapters
- Translations
- API representation (JSON:API) or otherwise
MR contents
- ** New Adapter plugin type and AdapterManager service **. Each plugin can:
-
addInput(string $input, mixed $itemBase)
- adds input to adapter instance -
adapt()
- adapts output -
outputSchemaMatch($schema)
- checks if$schema
matches output schema of the adaptor
-
Tests (minimal)
-
Kernel
Merge request reports
Activity
added 1 commit
- 421bf963 - refactor AdapterManager to use data shapes instead of field types
requested review from @wimleers
Can we get a rough outline of the intended use here - is it to replace SdcPropToFieldTypePropMatcher or is it for FieldForComponentSuggester in !20 (merged)?
Adapters will integrate with SdcPropToFieldTypePropMatcher - it's a way to apply business logic to raw data before it is passed to SDC props. For example, if SDC prop accepts an
image
data shape withsrc
,alt
,height
andwidth
properties one can use image stored infield_image
and default file URI as value forsrc
or select (or write new) adapter that would transformimage
by applying selected image style and use appropriate URI as value forsrc
.
added 9 commits
-
421bf963...d7e5f551 - 4 commits from branch
0.x
- 11750873 - Adapters PoC initial commit
- 1072809c - Adapter inputs based on data shape, not field types
- b7a256bc - Allow image uri to have itok token, add basic 'config entity id' schema
- 100ad4da - refactor AdapterManager to use data shapes instead of field types
- 2899fbbe - Added adapted prop source
Toggle commit list-
421bf963...d7e5f551 - 4 commits from branch
I’d swear there were changes to the matcher, I’d swear you talked to me about that, but I don’t see it right now, seemingly since the rebase atop
0.x
after !15 (merged) was merged?- Resolved by Feliksas Mazeikis
- Resolved by Feliksas Mazeikis
- Resolved by Feliksas Mazeikis
- Resolved by Feliksas Mazeikis
- Resolved by Feliksas Mazeikis
- Resolved by Feliksas Mazeikis
- Resolved by Feliksas Mazeikis
added 1 commit
- 724b2f70 - finding adapters to match sdc props by output schema
added 1 commit
- 9d30b703 - phpstan, phpcs and general cleanup related refactoring
added 4 commits
-
01d95420...791a7ef8 - 3 commits from branch
0.x
- 14acf5f2 - Merge remote-tracking branch 'origin/0.x' into research__adapters_poc
-
01d95420...791a7ef8 - 3 commits from branch
added 1 commit
- 281806d6 - Explicit sorting — plugin discovery orders is not guaranteed to have consistent ordering.
- src/Plugin/Adapters/Adapter.php 0 → 100644
12 * 13 * Plugin Namespace: Plugin\Adapter 14 * 15 * @see \Drupal\experience_builder\Plugin\Adapters\AdapterInterface 16 * @see \Drupal\experience_builder\Plugin\AdapterManager 17 * @see plugin_api 18 */ 19 #[\Attribute(\Attribute::TARGET_CLASS)] 20 class Adapter extends Plugin { 21 22 /** 23 * @param string $id 24 * @param \Drupal\Core\StringTranslation\TranslatableMarkup $label 25 * @param array<string, mixed> $inputs 26 * @param array<string> $requiredInputs 27 * @param string $output The output must not be a string per se — what if the output was for example{ "type": "string", "format": "uri" }
? That's perfectly valid, and is again a JSON schema. I recognize that this is currently a huge PITA with PHPStan. So I searched and … found https://phpstan.org/writing-php-code/phpdoc-types#local-type-aliases. Introducing that…Done: !16 (86ffc20f).
- Resolved by Wim Leers
- Resolved by Wim Leers
- src/Plugin/Adapters/AdapterBase.php 0 → 100644
57 $message = implode("/n", $message_parts); 58 throw new \Exception($message); 59 } 60 61 /** 62 * @return array<string, mixed> 63 */ 64 public function getOutputSchema(): array { 65 assert(is_array($this->getPluginDefinition())); 66 assert(array_key_exists('output', $this->getPluginDefinition())); 67 return json_decode((string) file_get_contents($this->getPluginDefinition()['output']), TRUE); 68 } 69 70 /** 71 * @todo: is there a better way? 72 */ changed this line in version 21 of the diff
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
- Resolved by Wim Leers
- src/Plugin/Adapters/Adapter.php 0 → 100644
12 * 13 * Plugin Namespace: Plugin\Adapter 14 * 15 * @see \Drupal\experience_builder\Plugin\Adapters\AdapterInterface 16 * @see \Drupal\experience_builder\Plugin\AdapterManager 17 * @see plugin_api 18 * 19 * @phpstan-import-type JsonSchema from \Drupal\experience_builder\SdcPropJsonSchemaType 20 */ 21 #[\Attribute(\Attribute::TARGET_CLASS)] 22 class Adapter extends Plugin { 23 24 /** 25 * @param string $id 26 * @param \Drupal\Core\StringTranslation\TranslatableMarkup $label 27 * @param array<string, array<string, mixed>> $inputs changed this line in version 21 of the diff
added 1 commit
- adf28671 - Remove boilerplate docs to satisfy PHPStan while it is caused by upstream — we...
added 1 commit
- 71b25b44 - Ignore the PHPStan errors triggered for `ContainerFactoryPluginInterface`...
- Resolved by Wim Leers
requested review from @tedbow
883 'imageStyle' => [], 884 ], 885 'image_url_rel_to_abs' => [ 886 'image' => ['ℹ︎image␟{src↝entity␜ℹ︎␜entity:file␝uri␞0␟value, alt↠alt, width↠width, height↠height}'], 887 ], 888 ], 889 // adapter - instance 890 'adapter_matches_instance' => [ 891 'image_apply_style' => [ 892 'image' => ['ℹ︎␜entity:node:foo␝field_silly_image␞␟{src↝entity␜ℹ︎␜entity:file␝uri␞␟value, alt↠alt, width↠width, height↠height}'], 893 'imageStyle' => [], 894 ], 895 'image_url_rel_to_abs' => [ 896 'image' => ['ℹ︎␜entity:node:foo␝field_silly_image␞␟{src↝entity␜ℹ︎␜entity:file␝uri␞␟value, alt↠alt, width↠width, height↠height}'], 897 ], 898 ], mentioned in merge request !20 (merged)
assigned to @larowlan