-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/7.3' into 8.0
- Loading branch information
Showing
6 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
.../Editors/SelectBox/createSelectBoxValueStringFromPossiblyStrangeNodePropertyValue.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {createSelectBoxValueStringFromPossiblyStrangeNodePropertyValue} from './createSelectBoxValueStringFromPossiblyStrangeNodePropertyValue'; | ||
|
||
describe('createSelectBoxValueStringFromPossiblyStrangeNodePropertyValue', () => { | ||
it('accepts value of type "string" and returns a "string"', () => { | ||
const value = | ||
createSelectBoxValueStringFromPossiblyStrangeNodePropertyValue( | ||
'I am already a valid select box value, believe it or not.' | ||
); | ||
|
||
expect(value).toEqual( | ||
'I am already a valid select box value, believe it or not.' | ||
); | ||
}); | ||
|
||
it('accepts an object identity DTO and returns a "string"', () => { | ||
const value = | ||
createSelectBoxValueStringFromPossiblyStrangeNodePropertyValue({ | ||
__identity: 'de93b358-cb77-422e-b295-2f219bfc4dfb', | ||
__type: 'Neos\\Media\\Domain\\Model\\Tag', | ||
}); | ||
|
||
expect(value).toEqual('de93b358-cb77-422e-b295-2f219bfc4dfb'); | ||
}); | ||
}); |
36 changes: 36 additions & 0 deletions
36
...s/src/Editors/SelectBox/createSelectBoxValueStringFromPossiblyStrangeNodePropertyValue.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @TODO I am a cry for help! | ||
* | ||
* This is an ad-hoc solution to the problem that properties of a PHP class type | ||
* (like "Neos\Media\Domain\Model\Tag" for example) may or may not be persisted | ||
* as object identity DTOs. | ||
* | ||
* The function name is intentionally kept vague to allow bugfixes to capture | ||
* more, potentially obscure cases in which the persisted property value needs | ||
* to be filtered before the select box receives it. | ||
* | ||
* A proper way to handle this would be to define precisely what kind of values | ||
* the select box editor is going to accept and simply reject everything that | ||
* violates that definition. Errors would need to be handled in way that | ||
* indicates to editors that there's a problem that an integrator needs to fix. | ||
* Furthermore the error handling should make it easy for integrators to figure | ||
* out what value has been provided to the select box and why it has been | ||
* rejected. | ||
* | ||
* That however would constitute a breaking change and that's how we end up | ||
* with with this function. | ||
*/ | ||
export const createSelectBoxValueStringFromPossiblyStrangeNodePropertyValue = ( | ||
value: unknown | ||
) => { | ||
if (typeof value === 'object' && value !== null) { | ||
if ( | ||
'__identity' in value && | ||
typeof (value as Record<'__identity', any>).__identity === 'string' | ||
) { | ||
return (value as Record<'__identity', string>).__identity; | ||
} | ||
} | ||
|
||
return value; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters