Core Drupal 8 has a "string" datatype. But that is the only core datatype provided for text data. There is a need in many module, Rules for instance, to distinguish between 'short' text and 'long' text. Both the core Configuration API and the core Field API make this distinction, but that was never put into the core Typed Data API. The difference is essentially that 'short' text is entered using a textfield, while 'long' text is entered using a textarea. Otherwise, they are functionally the same.
The whole purpose of the Typed Data API Enhancements module (typed_data) is to add extensions, enhancements, and missing features to the core Typed Data API. The typed_data module already provides a textarea form widget, and I propose we also need a new "text" datatype - this is essentially a missing core feature.
Here is a patch that provides this new "text" datatype. I would prefer to have tests, but since it is an extension of the "string" datatype with no new functionality I'm not sure what could be tested other than the type can be found and instantiated.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3091923-3.interdiff.txt | 481 bytes | jonathan1055 |
| #3 | 3091923-3.text-datatype.patch | 3.94 KB | jonathan1055 |
Comments
Comment #2
jonathan1055 commentedThanks @TR. This is good solution to the problem I discovered in #2724129-58: Change message field to textarea in Send email action
I applied the patch and started to implement the changes but discovered that the class names were not quite right. Hence I took up your advice and added a test to instantiate the datatype and perform basic set and get methods. I have got the corrected code, but here first is the new test added to your original patch, and we should see a 'Class not found' error.
Comment #3
jonathan1055 commentedIn addition to the first message
when this is fixed locally we also get:
Looking at the Core datatype definitions I think we need to change
Drupal\Core\TypedData\Type\StringDatato
Drupal\Core\TypedData\Plugin\DataType\StringDataand change
Drupal\typed_data\Type\TextInterfaceto
Drupal\typed_data\TypedData\Type\TextInterfaceComment #4
tr commentedYeah that was stupid of me. You can tell I didn't test it at all. Thanks for the correction and for the test - that should help a lot!
Comment #5
jonathan1055 commentedNo apology needed. I did not know where to start, I did not even think about creating a new data type. So thank you for this, now we are making real progress. My changes to use the Typed Data widgets are coming along OK. The new 'text' type works fine and the e-mail field is now a textarea without Rules having to know that it is.
However, it has failed on a few automated tests, and also in my manual testing when switching to data-selection from direct-input. So, a bit more work to do ...
Marking this RTBC as it will be needed when I come to test the changes on d.o. We can make any adjustments later if needed.
Comment #6
tr commentedI'm going to hold off on committing this until I get a chance to manually use it and see if it causes problems. Hopefully this week.
I will also have to make a new fixed-point release of this module in order to push this change out to the majority of the user base. I will want to finish up a few other things to go with that new release (I will open issues and post patches for those later today). Additionally, D8.6 will become officially unsupported as of 4 December, which will give us an opportunity to get rid of anything that was introduced and deprecated in D8.7 but not backported. So I think the plan should be to make the release on 4 December.
Comment #8
tr commentedCommitted. Thanks!
Comment #9
jonathan1055 commentedGood, thank you, I can use this in #2471481: Integrate Typed Data Widgets now, but also I understand that it wont be generally available until you release 8.x-1.0-alpha4. Or are we in a position to release 8.x-1.0-beta1? No hurry as I know you have other issues to work on before the release.
Comment #10
tr commentedI think my plan is still going to be what I said in #3093191: Plan for Typed Data release 8.x-1.0-alpha4: Basically, a new alpha release when Drupal core 8.6.x becomes unsupported, which is planned for 4 December.
After that, I hope to get some necessary features in before a beta release. I'm happy to make a beta release in a month or two if those features are complete. I think it would be nice to have a checkbox form element to use for boolean context parameters, for example.
The only beta blocker issues at this point are:
#2847801: [META] Complete typed data widgets and #2871406: Add checkboxes/radios input widgets, although that first one has a number of sub-tasks.
Further discussion of "must-have" features should probably take place in #2847801: [META] Complete typed data widgets. IMO any issue that changes the API for this module should be a beta blocker because I really don't need the hassle of writing update hooks and upgrade tests for API changes. New features are fine in beta, I just don't want to be changing the API once we get to beta. Anyway, to be continued in #2847801: [META] Complete typed data widgets ...
Comment #11
jonathan1055 commentedThanks for the extra info. Yes, I get and agree with your plan re- beta release.
I've followed those issue and will contribute where I can