Certain fields cannot be attached to certain entities.
For instance "comment_body" field can only be attached to comments.
If you try to clone "comment body" to another entity you will get the fatal error something like
FieldException: Attempt to create an instance of field comment_body on forbidden entity type entityform. in field_create_instance()
I will provide a patch to fix this
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | field_tools-check_field_can_attach-1604768-3.patch | 2.76 KB | tedbow |
| #1 | field_tools-check_field_can_attach-1604768-1.patch | 1.54 KB | tedbow |
Comments
Comment #1
tedbowAttaching patch
Creates helper function "_field_tools_entity_can_attach_field"
This function was also added here #1604704: Clone fields from various bundles into 1 bundle
Comment #2
joachim commentedGood point; I never thought of that!
Patch looks good, though could you run it through Coder module please to fix docblock formatting, constants, and whitespace please?
Also:
Let's just say this always has to be a $field_info. It's cleaner to not have mixed purpose params, and it's no great burden on a caller to have to load the field info first; callers will usually have it.
Comment #3
tedbowOk, ran through and fixed whitespace errors
Comment #4
joachim commentedYour docblock still wasn't laid out quite right; I've committed it with a bit of tidying up.
For reference, this is how docblocks should be laid out (at least last time I checked coding standards... which do change!)
- #1604768 by tedbow: Fixed lack of check that fields aren't restricted to certain entity types.
Thanks again for the patch!