Problem/Motivation

Would it be possible to add a way to choose which formats are allowed per token types?
And which one should be selected per default?

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

macsim created an issue. See original summary.

macsim’s picture

Issue summary: View changes
anybody’s picture

Priority: Normal » Minor

@macsim feel free to prepare a MR with that functionality or solve it in contrib / custom. Seems a very edge-case?

longwave’s picture

This would actually be useful to me as I have a set of tokens that should only be plain text, for now I've worked around it with a form alter hook.

anybody’s picture

Wouldn't contrib https://www.drupal.org/project/allowed_formats fix this? Has someone tried?

I still think this might be an edge-case for which https://www.drupal.org/project/allowed_formats has been made?

longwave’s picture

Allowed formats is in core now, but as far as I can see it only works for configurable fields, and the content field on a custom token is a base field.

I tried adding

field_ui_base_route = "entity.token_custom_type.edit_form",

to the TokenCustom entity type annotation, which exposes Field UI on the token custom type edit form and allows you to add new fields to custom token bundles, and even change the widget for the content field, but as far as I can see there is no way of editing the settings of the content field itself.

anybody’s picture

Sorry @longwave you're right! I thought it was a "body" field.

So maybe it's somehow related to #2353867: [META] Expose Title and other base fields in Manage Display or we could alternatively change the content into a real richt text field?

longwave’s picture

StatusFileSize
new51.71 KB

https://www.drupal.org/project/base_field_override_ui works! If I make the change in #6 and enable Base Field Override UI then the content field settings can be overridden:

Will open an MR for the Field UI change, I think that's all that needs to happen.

longwave’s picture

Status: Active » Needs review
anybody’s picture

Whao, nice catch @longwave! Any risks of side-effects you see? Otherwise this LGTM and I'd be fine to merge this!

longwave’s picture

I don't think so.. I mean I am not sure it is much use allowing the rest of field UI here - what does it mean to add additional fields to a custom token? - but otherwise everything seems to work fine. Perhaps someone has some use for custom fields on a token somewhere...

anybody’s picture

Status: Needs review » Reviewed & tested by the community

Ok I also can't see risks, so let's do it :)

anybody’s picture

Let's keep it in dev for a while... @macsim please give it a try!

anybody’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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

macsim’s picture

Sorry guys it's been a long time I didn't came here.

Just gave a try to that solution using Token custom 8.x-1.x-dev + Base Field Override UI 8.x-1.2 on a Drupal 11.3 and it works like a charm - thanks @longwave for the tip and merge request.
I am now able to choose which formats are allowed on a given custom token type :)

@anybody with all my due respect, usually the reporter should also be in the contribution records

anybody’s picture

Thanks for the feedback @macsim.

Regarding your comment for the contribution record... well I don't see a problem granting you the credits and don't want to be stingy with you, but it's just a feature request in one sentence, so I think the community served you and not the other way around?

Please don't take this personally or anything, I mean this totally objective. If you provided a first MR, patch or at least the key solution, I would definitely have done so...

If @longwave thinks my decision was wrong here, please correct me.

I absolutely don't want to be unfair!

macsim’s picture

Honestly, I don't mind ; it was just an idea to improve the module. I am glad I was not alone who thought it would have been necessary to limit certain types of custom tokens to plain text (or any other text format), and happier the feature has been implemented even if we have to install another module to reach the goal.

Don't worry, I don't take it personally :-) I just see things differently: by creating the feature request, the reporter - even if he didn't made a MR / patch / review / or propose a solution - is the first entrypoint to that improvment that's why I usually give him credit as well.
I'll do more next time ;-)

Thanks again @longwave

anybody’s picture

As written I didnt want to be stingy and you're still active here and tested the result, so let's do it. I granted you credit.

Thanks for taking the time for reply @macsim, I hope you understand my point. Let's just keep pushing Drupal and open source together :)