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.

Comments

TR created an issue. See original summary.

jonathan1055’s picture

Issue tags: -Needs tests
StatusFileSize
new4.17 KB

Thanks @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.

jonathan1055’s picture

Title: Add a new "text" datatype » Add a new "text" datatype for long text
StatusFileSize
new3.94 KB
new481 bytes

In addition to the first message

Fatal error: Class 'Drupal\Core\TypedData\Type\StringData' not found in /typed_data/src/Plugin/DataType/TextData.php on line 26

when this is fixed locally we also get:

Fatal error: Interface 'Drupal\typed_data\Type\TextInterface' not found in /typed_data/src/Plugin/DataType/TextData.php on line 27

Looking at the Core datatype definitions I think we need to change
Drupal\Core\TypedData\Type\StringData
to
Drupal\Core\TypedData\Plugin\DataType\StringData

and change
Drupal\typed_data\Type\TextInterface
to
Drupal\typed_data\TypedData\Type\TextInterface

tr’s picture

Yeah 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!

jonathan1055’s picture

Status: Needs review » Reviewed & tested by the community

Yeah that was stupid of me. You can tell I didn't test it at all.

No 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.

tr’s picture

I'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.

  • TR committed cbfaa92 on 8.x-1.x authored by jonathan1055
    Issue #3091923 by TR, jonathan1055: Add a new "text" datatype for long...
tr’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thanks!

jonathan1055’s picture

Good, 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.

tr’s picture

I 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 ...

jonathan1055’s picture

Thanks 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

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.