Allow text field to enforce a specific text format

Created on 28 April 2010, about 14 years ago
Updated 5 December 2023, 6 months ago

Problem/Motivation

Currently text fields can either be restricted to plain text, or the user may select between all accessible text formats independently of the context. This means that a privileged user who needs access to a permissive text formats (for example, to put tables or embedded remote content in basic pages) will get access to that format on every formatted text field (for example on a comment field).

There are three problems with this approach, and most experience Drupal developers have faced at least one of those in the past:

Proposed resolution

Add an optional setting to the text field types that lets the site-builder determine if the text formats should be restricted. This setting is then used in the default textfield and textarea widgets to remove any non-allowed text formats. If nothing is set, the current behavior is unchanged.

Note that as it uses the underlying '#allowed_formats' form API property, the settings can't be used to give access to text formats that the user wouldn't have access to otherwise.

Remaining tasks

1) Review and commit 🀞

User interface changes

Checkboxes on list of available formats on text field configuration. Reduced set of allowed formats on content edit forms, where used. No fields use the new setting by default, so the patch doesn't affect the user interface for those who don't do anything with this functionality.

API changes

None

Data model changes

One setting is added to the field settings. The structure of the field data is unchanged.

Release notes snippet

Site builders can now limit which input formats are available on a per-field basis.

✨ Feature request
Status

Fixed

Version

10.1 ✨

Component
TextΒ  β†’

Last updated 9 days ago

Created by

πŸ‡©πŸ‡°Denmark c960657

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany vistree

    Patch from #302 works on 9.5.3

  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    Re-roll for Drupal 10.0.7, just so that it still can be applied

  • πŸ‡ΊπŸ‡ΈUnited States W01F

    Noting that this change doesn't seem to apply for default taxonomy description fields. It doesn't appear you can limit the allowed formats. I think this issue may also be related - https://www.drupal.org/project/drupal/issues/3106303 πŸ› Taxonomy term description field format not takes in account Active .

  • πŸ‡«πŸ‡·France steveoriol Grenoble πŸ‡«πŸ‡·

    Patch from #302 works on 9.5.9 but break the site with D9.5.10...

    This is the Apache2 error log :

    AH01071: Got error 'PHP message: Error: Class "
    \\Drupal\\text\\Plugin\\Field\\FieldType\\TextFieldItemList" not found in /var/www/drupalwebsite/web/core/lib/Drupal/Core/TypedData/TypedDataManager.php on line 91 
    #0 /var/www/drupalwebsite/web/core/lib/Drupal/Core/TypedData/TypedDataManager.php(103): Drupal\\Core\\TypedData\\TypedDataManager->createInstance()\n#1 /var/www/drupalwebsite/web/core/lib/Drupal/Core/TypedData/TypedDataManager.php(200): Drupal\\Core\\TypedData\\TypedDataManager->create()\n#2 /var/www/drupalwebsite/web/core/lib/Drupal/Core/Field/FieldTypePluginManager.php(74): Drupal\\Core\\TypedData\\TypedDataManager->getPropertyInstance()\n#3 /var/www/drupalwebsite/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php(604): Drupal\\Core\\Field\\FieldTypePluginManager->createFieldItemList()\n#4 /var/www/drupalwebsite/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php(568): Drupal\\Core\\Entity\\ContentEntityBase->getTranslatedField()\n#5 /var/www/drupalwebsite/web/core/lib/Drupal/Core/Entity/EntityViewBui...'
  • πŸ‡¨πŸ‡¦Canada djac

    Patch from #302 is working as expected in our D9 (9.5.10) environment.

    @steveoriol perhaps you can include some information about your field setup and steps to reproduce the error you're encountering?

  • Has anybody encountered this error ?
    I ran into this error everytime while I trying to access the front page on my Drupal 10.1.6 site.
    It's seen to be the same error with #307...
    Any suggestions? many thanks!!!

    Error: Class "\Drupal\text\Plugin\Field\FieldType\TextFieldItemList" not found in Drupal\Core\TypedData\TypedDataManager->createInstance() (line 91 of /userap/httpd/htdocs/drupal/web/core/lib/Drupal/Core/TypedData/TypedDataManager.php) #0 /userap/httpd/htdocs/drupal/web/core/lib/Drupal/Core/TypedData/TypedDataManager.php(103): Drupal\Core\TypedData\TypedDataManager->createInstance('list', Array)

Production build 0.69.0 2024