This is a follow-up of #2224643: Support for input format configuration on a per-field basis .
Problem/Motivation
When transferring content from one Drupal website to another it can be handy if the source can decide which text format should be used. This idea is originally proposed by hanoii in #2224643: Support for input format configuration on a per-field basis .
Proposed resolution
A new mapper is introduced, which allows one to map to text format directly. As allowing just any format could introduce security issues, there is a mapping configuration option which with you can set the allowed formats (thanks to hanoii by providing this idea in #2224643-18: Support for input format configuration on a per-field basis ). By default, only the default text format is allowed (to reduce the chance that users will accidently insecure their website). The mapper will only be available for text fields that have "Text processing" set to "Filtered text (user selects text format)".
Remaining tasks
- Reroll/Rewrite of patch in #2224643-18: Support for input format configuration on a per-field basis
- Automated tests
User interface changes
A mapper that allows you to map to text format will be available from the list of mappers to choose from if you have text fields that have "Text processing" set to "Filtered text (user selects text format)".
API changes
None.
I'll plan to work on this and hopefully provide a first patch next week.
Comment | File | Size | Author |
---|---|---|---|
#2 | interdiff-2309273-1-2.txt | 18.46 KB | MegaChriz |
#2 | feeds-text-format-mapping-2309273-2.patch | 22.56 KB | MegaChriz |
#1 | feeds-text-format-mapping-2309273-1.patch | 12.38 KB | MegaChriz |
Comments
Comment #1
MegaChriz CreditAttribution: MegaChriz commentedThe attached patch adds a target for mapping to text format for a text field.
Mapping to format vs format target configuration
One of the problems that I faced was that the target configuration "format" for the "value" part of text fields could overwrite the mapped value, depending on the order of mappings. Let me illustrate this with an example:
At first, this resulted into the body format becoming "Plain text", because the second mapper also did set the format for the body field.
To solve this problem I added the following code line to keep track of whether or not the mapping to format had taken place:
Changes to FeedsWebTestCase::addMappings()
The format target has configuration for setting the formats to accept from the source (this exists to prevent the source from setting any text format, which would be a security issue if, for example, the php text format is available). The config option "allowed_formats" accepts multiple values, but
FeedsWebTestCase::addMappings()
assumed all target configurations were single-valued, so that's why I had to adjust this method in order for the automated tests to work.Automated tests
A new test case called "FeedsMapperFormatTestCase" is added. This contains two test methods:
This also tests if:
The following is not yet covered by the automated tests and may need to be added:
I hope to extend the tests later.
Comment #2
MegaChriz CreditAttribution: MegaChriz commentedI have completed the automated tests for mapping to text format. I also slightly changed the implementation of the format mapper.
Summary of the changes:
text_feeds_format_defaults()
to not having to repeat the default target configuration for format targets.More details about the working of the tests can be found in the code comments.
I think this is ready.
Comment #3
tyler.frankenstein CreditAttribution: tyler.frankenstein commentedIn the mean time, it's possible to set the input format for your field using Rules.