Add support for rich text fields and custom validation messages#164
Open
redjam13 wants to merge 5 commits intocontentful:masterfrom
Open
Add support for rich text fields and custom validation messages#164redjam13 wants to merge 5 commits intocontentful:masterfrom
redjam13 wants to merge 5 commits intocontentful:masterfrom
Conversation
…, enabled node types)
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I took my first foray into using this SDK yesterday but quickly ran into issues. Namely:
The
NodesValidation::jsonSerializemethod is hardcoded to return[], however an object is expected as evidenced by the response:I can see that the justification for this change was that the empty
nodesobject is always present when retrieving rich text content types. My proposed solution here is instead just to ignore the emptynodesobject fromvalidationswhen mapping the response.nodes,enabledMarksandenabledNodeTypes) all suffer from the above problem - and presumably even if the intention of the existing code worked correctly, we would be overwriting any defined validations by hardcoding this to be empty?I've made a first pass at implementing the correct validations for a rich text field.
Custom validation messages on fields are overwritten (emptied) when updating a content type
Fields which have a custom validation message - where the validation key comes after
messagealphanumerically e.g.size- will throw an exception (MessageValidationclass not found)The
BaseField::mapValidation()method assumes the first key will correspond tosize,range, etc (seearray_keys($data)[0]) however this is not true where amessageis included.Ostensibly these last two bugs have always existed but have somehow gone unnoticed; I can only assume adding custom validation messages isn't a commonly-used feature 😄
I'm not yet completely au fait with the code here and I'm not precious about the implementation details of these fixes so I am of course happy for any of this to be adapted by others if necessary - or to make further changes upon feedback :)