Project Name:

Field Embed

Description:

The Field Embed module allows you to embed a field within another field. This is best used when you need to include complex field layering in a WYSIWYG, or if you have a special style to apply to fields if they're inside main WYSIWYG content (such as an inner-rail on an article page).

Project Page:

https://www.drupal.org/sandbox/mredding/2294099

Pareview

OK: http://pareview.sh/pareview/httpgitdrupalorgsandboxmredding2294099git

clone cmd:

git clone --branch 7.x-1.x http://git.drupal.org/sandbox/mredding/2294099.git field_embed
cd field_embed

Drupal version:

7.x

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mredding’s picture

Issue summary: View changes
PA robot’s picture

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

pkamerakodi’s picture

Hi,

Please find some review comments which i felt like would be better to update.

1) In theme_field_embed can we try to return renderrable arrays and instead of use html markup we can try use theme_html_tag function.

2) In field_embed_form_alter i think it is better to add a check for form id

3) In field_embed_validate_fields line number 299 please add a isset check to avoid warning.

4) Line 308 add a check of if the input variable is an array

5) Same in template_process_field_embed line 211 add a isset condition before implode.

Please let me know if have any concerns.

pkamerakodi’s picture

Status: Needs review » Needs work
mredding’s picture

Hi! Thanks for the feedback.

1. This is actually taken from the default field process functions, so I don't think it's advisable to make this a render array. The idea here is that themers can take what they know from core and apply it to field_embed.

2. The problem with checking against $form_id here is that we don't know a $form_id that may have elements that need validation. The validator has sanity checks to prevent trying to validate unknown form fields. This is similar to how node_embed checks to make sure you're not embedding a node into itself.

3. Fixed.

4. Fixed.

5. Fixed.

See http://cgit.drupalcode.org/sandbox-mredding-2294099/commit/?id=2c6ba9e51... for code updates.

mredding’s picture

Status: Needs work » Needs review
IcreonGlobal’s picture

I am getting following notices in your module when creating any node.

Notice: Undefined property: stdClass::$bundle_name in field_embed_validate_fields() (line 290 of C:\xampp\htdocs\dev725\sites\all\modules\field_embed\field_embed.module).
Notice: Undefined property: stdClass::$entity_type in field_embed_validate_fields() (line 290 of C:\xampp\htdocs\dev725\sites\all\modules\field_embed\field_embed.module).

Thanks

mredding’s picture

Good catch. I've modified the module to use hook_field_attach_form to ensure those properties will always be set on validate.

joachim’s picture

Status: Needs review » Postponed (maintainer needs more info)

Wouldn't this be doable with https://www.drupal.org/project/token_filter?

mredding’s picture

Thanks joachim for the feedback. Token Filter provides access to global site tokens in embeds (such as site name, user information, etc.), while this module provides the ability to embed a field & view mode into another field. They're related, but this provides different functionality.

Token Filter would be useful for needing to put the site's title in a node (so that way if the site gets renamed, an 'About this Site' page could be easily renamed without having to edit the site).

Field Embed allows you to embed a field in another field (i.e., you want to put a 'Main Image' field as an embed into the body field on a page with a certain view mode).

mredding’s picture

Status: Postponed (maintainer needs more info) » Needs review
Bartuc’s picture

Status: Needs review » Needs work

Hello,

Your clone command should be: git clone --branch 7.x-1.x http://git.drupal.org/sandbox/mredding/2294099.git
Otherwise we get prompted for a password. Also you should update your project name from 2294099 to field_embed.

field_embed.module
line 54: If you are just returning text, why take 6 additional parameters? You should remove the ones that are not being used.
line 65: Same issue as above.
line 76: Same issue as above.
line 90: You should check to make sure $matches is an array or at least $matches[0] exists.
line 139: extra newline character.
line 229: You should build a render array in this function. You want to avoid typing out HTML if possible. This is not manipulative without the use of a render array. No other modules or themes could alter this code.
line 251: extra newline character.

That is all I could find at first glance. Please let me know if you have any questions.

* For parameters you are using, you should add a @param to the documentation header.

mredding’s picture

Issue summary: View changes
mredding’s picture

Status: Needs work » Needs review

Hi! Thanks for the feedback -- I've made your changes. I don't have the permissions to change the short_name of the project yet, so that's the only fix I haven't made.

ShaxA’s picture

1. Do you need this line because i think prepare is only needed if it is doing something:
-'prepare callback' => 'field_embed_filter_field_embed_prepare',

2. Be sure to avoid the word "and" and "or" in php.
And at all this line is completly unuseful because your $matches is always isset and you cannot call it if $matches is not an array as
you have declared the function as so.
- if (isset($matches) and is_array($matches)) {

3. You use often $matches[0] and $matches[1] which can result in notice

4. After enabling the module and added it for text formats then saved an empty body content it results with this:
Notice: Undefined index: #validate in field_embed_field_attach_form() (line 360 of E:\localhost\htdocs\drupal-test\sites\all\modules\contrib\field_embed\field_embed.module).
Warning: array_merge(): Argument #2 is not an array in field_embed_field_attach_form() (line 360 of E:\localhost\htdocs\drupal-test\sites\all\modules\contrib\field_embed\field_embed.module).

This is a startup review. I mean that when i stopped testing it after this errors so you can fix them and then i can continue

mredding’s picture

1. You're right. D7 doesn't require the callback if nothing's being done with the callback.

2. Changed. This reverts a fix suggested in #12, though you're right about the callback never firing. Superfluous code has been remvoed.

3. Added some isset checks.

4. Should be fixed now. Not sure what was causing that problem, but you should be good to go to on checking.

jeffam’s picture

Status: Needs review » Needs work

This is a pretty interesting idea. I can think of a few uses, such as adding an image field multiple times to a page and using multiple view modes to change the image style used.

Since the automated review has already been done, I thought that I would focus on some usability testing and manual code review.

Usability

My primary thought about the module is that discovering which fields are available requires some pretty technical knowledge of the node structure. What if the input filter help text was dynamic? As in something like this:

You may embed the following fields here:

- Tags: [[field:field_tags]]
- Image: [[field:field_image]]

You'd probably want to add some text about the optional view mode parameter, too, or even list them as well. And you probably wouldn't want to list the field into which you're about to embed another field, though it would be hard to detect. In fact, I wonder...

Ah. I see you check for that ('You cannot embed body inside itself'). Well done!

So I tested on an instance of simplytest.me using the core Article content type from the standard install profile.

It occurred to me that a common use case might be to hide the field (via Manage Display) and embed it in, say, the body field instead. When I tried this (I embedded field_tags into the body field), and then hid field_tags (via admin/structure/types/manage/article/display), I got a couple of errors:

  • Notice: Undefined index: taxonomy_term in taxonomy_field_formatter_view() (line 1601 of /home/s4291a7bcbef258e/www/modules/taxonomy/taxonomy.module).
  • EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7729 of /home/s4291a7bcbef258e/www/includes/common.inc).

When I tested with field_image, I noticed that the embed token [[field:...]] appears if the field has no value. Not sure what I'd expect, but not the token.

The field label also appeared when I tested with the image, even though it's set to be hidden in the view mode. I see that could be the job of the template, but even still, with the `$label_hidden` template variable, it should honor the hidden label setting of the view mode.

Manual code review

I see you have both theme_field_embed() and field-embed.tpl.php. Are both necessary?

The five level nested foreach loop in field_embed_field_form_validate() is insane! I think it's great that you hunt for self-referencing embeds, but you might consider searching for a way to validate only fields that have the input filter on them (e.g. textareas).

It also feels sketchy to add two properties (->entity_type and ->bundle_name) to all entities. Seems a bit intrusive and unwarranted for the objectives of this module. Again, it looks like this in service of the validation, so if there were, perhaps, a more targeted way to validate only fields that _could_ have embed codes in them, this would be unnecessary. At the very least, you might consider prefixing them with your module name (e.g. ->field_embed_entity_type) to avoid any potential conflicts.

That's what I got. Good luck! I could see using this on a project eventually.

mredding’s picture

Hi Jeff! See below for my comments.

My primary thought about the module is that discovering which fields are available requires some pretty technical knowledge of the node structure. What if the input filter help text was dynamic? As in something like this:

You may embed the following fields here:
- Tags: [[field:field_tags]]
- Image: [[field:field_image]]
You'd probably want to add some text about the optional view mode parameter, too, or even list them as well.

You're absolutely right. Longer-term, I'd like to update the module to also include some WYSIWYG & CKEditor plugins to make this super easy, but for now, I've added in this suggestion. I also realized that the text wasn't clear about the view mode (I meant field formatter), so I've updated the helper text to make it clear that this is formatter mode.

Notice: Undefined index: taxonomy_term in taxonomy_field_formatter_view() (line 1601 of /home/s4291a7bcbef258e/www/modules/taxonomy/taxonomy.module).
EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7729 of /home/s4291a7bcbef258e/www/includes/common.inc).
When I tested with field_image, I noticed that the embed token [[field:...]] appears if the field has no value. Not sure what I'd expect, but not the token.

The field label also appeared when I tested with the image, even though it's set to be hidden in the view mode. I see that could be the job of the template, but even still, with the `$label_hidden` template variable, it should honor the hidden label setting of the view mode.

Yea, that was an error in my logic. Because field_formatter_prepare_view is what generates 'taxonomy_term' as an element of the array, I've added in some crazy-complicated logic to basically trick the Field API into ignoring the 'display' attribute from the Manage Displays screen, while still respecting label display. This also affected things like EntityReference field types. This should now be fixed.

I see you have both theme_field_embed() and field-embed.tpl.php. Are both necessary?

field-embed.tpl.php is provided for themers as an example, much like how field.tpl.php is provided by core as an example.

The five level nested foreach loop in field_embed_field_form_validate() is insane! I think it's great that you hunt for self-referencing embeds, but you might consider searching for a way to validate only fields that have the input filter on them (e.g. textareas).

Checking against fields with #format only now, and using recursion to eliminate these crazy loops.

It also feels sketchy to add two properties (->entity_type and ->bundle_name) to all entities. Seems a bit intrusive and unwarranted for the objectives of this module. Again, it looks like this in service of the validation, so if there were, perhaps, a more targeted way to validate only fields that _could_ have embed codes in them, this would be unnecessary. At the very least, you might consider prefixing them with your module name (e.g. ->field_embed_entity_type) to avoid any potential conflicts.

Agreed, but necessary for the validation. Ideally D7 core would expose entity_type and bundle_name on all entities by default, but alas... Regardless, I've namespaced these to this specific module.

Thanks for the review!

mredding’s picture

Status: Needs work » Needs review
jeffam’s picture

Status: Needs review » Needs work

Hi Michael,

Just went to take another look and noticed a new error on a clean install. I get it every time I create a new node of any type, even if it isn't using a text format with the field embed input filter on it.

Recoverable fatal error: Argument 1 passed to _field_embed_value_check_field() must be an array, string given, called in /home/s575153226a8af1e/www/sites/default/modules/2294099/field_embed.module on line 575 and defined in _field_embed_value_check_field() (line 554 of /home/s575153226a8af1e/www/sites/default/modules/2294099/field_embed.module).

Even before that error, I noticed that the input filter help text doesn't appear when creating new nodes. I wonder if the menu_get_object() call can't return anything unless one is editing an existing node.

mredding’s picture

Hey Jeff! Absolutely right on that error. Didn't have the proper conditional to prevent further recursion.

As far as getting field tips on creating new nodes, I added in an extra hack to make it work for node. The trick is going to be for other entity types (such as taxonomy term or user), since there's not a standard in Drupal for getting the entity type from the menu item.

mredding’s picture

Status: Needs work » Needs review
jeffam’s picture

Status: Needs review » Needs work
FileSize
22.71 KB

Hi Michael,

So sorry about my delay in getting back to you. Just tested again on simpletest.me, again using the Article content type.

This module is pretty slick. There are no more errors, the help text is, well, really helpful, and embedding the image and term reference fields worked great for me.

One thing didn't work as expected: The tokens didn't render when I viewed the node on the home page as a teaser:

screenshot

mredding’s picture

Hi Jeff!

Sorry for not getting back to you as well. I think I'm going to have to push back on whether it's expected behavior for the field embed filter to work on the teaser view. This would break core functionality of the text_summary function (which is used to generate the node teasers), since only core filters are called by that function (specifically checking if there's PHP code in the text OR if HTML corrector filter is applied).

I agree that applying this filter in a node teaser would be useful, but I think the solve would be better served by putting in a patch to core to ensure that text_summary calls all filters, rather than in this module, breaking core functionality.

mredding’s picture

Status: Needs work » Needs review
jeffam’s picture

Status: Needs review » Needs work

Hi Michael,

I hear you, and I know it must seem like I'm pushing back a bit much, but after a quick test, both Insert Block and Insert View process the embed token in the summary field. If they can do it, so can you.

But if you wanted to push back and add it as a known issue to your project, I could live with that.

Mainly it makes me wonder if your input filter is implemented properly, or if Insert Block and Insert View needed to somehow work around the issue.

mredding’s picture

Ah, I see how those modules implement this. Those modules take parameters that let the user select what gets loaded. For markup sake, I had removed an NID parameter from the field embed, since I didn't want the module to get crazy with being able to include Field A from Node 1 in Field B of Node 2. Thus, we use menu_get_object() to grab the current entity. Because the teaser view shows up without a menu, it doesn't load.

To counter this, I've modified the field embed code to use [[ENTITY_TYPE=ENTITY_ID:FIELD_NAME:FORMATTER]] rather than [[field:FIELD_NAME:FORMATTER]]. I'm worried this adds extra complexity, but it does solve a lot of the other problems discussed above. I've gone ahead and made this change, and everything does appear to be working now.

mredding’s picture

Status: Needs work » Needs review
uberhacker’s picture

FileSize
24.37 KB

Hey Michael,
Awesome module and excellent work following best practices. In order to get this module moving forward so you can have commit access on d.o, I have completed a PAReview as outlined at https://groups.drupal.org/node/427683 and attached a patch which addresses a few issues. Let me know what you think.
Thanks

Explanation of patch changes below:

 - Fixed a bug that appears when creating a new entity as shown below:
   Notice: Undefined variable: entity in field_embed_filter_field_embed_tips() (line 75 of field_embed.module).
 - Reformatted the array that outputs help text to use parameters instead of string concatenation in the t() function.
 - Rearranged the help text to display the full filter for formatter options in order to make it more clear and easier to cut and paste.
 - Changed the help text to only display formatter options for fields with multiple formatters since the default is redundant.
 - Changed references from node to entity in the help text.
 - Added sections to README.txt.
 - Added LICENSE.txt.
mredding’s picture

Thanks for the patch! Yea, the tips logic was a bit buggy, thanks for the catch. And good eye on the labeling. I've applied the patch and made a couple more formatting updates throughout.

Thanks for the review!

uberhacker’s picture

Hey Michael,
I did notice one other issue. On line 168 of field_embed.module, $original is undefined. I've tested this and it doesn't appear to affect the functionality but maybe just a simple return; line would work? According to php.net, the preg_replace_callback function should return the original string if no matches are found. See the Return Values section at http://php.net/manual/en/function.preg-replace-callback.php. I imagine if $original is not defined, it could potentially spew some messages in the log but I haven't noticed anything while testing. Do you know how to write simpletests? That may help get it to a fully baked state. But I think it might be good enough to submit as is. We can always add issues in the queue of other things we notice. I would say this is ready to go and RTBC.
Thanks

uberhacker’s picture

Status: Needs review » Reviewed & tested by the community
mredding’s picture

Priority: Normal » Major
kscheirer’s picture

Priority: Major » Normal

Fixing priority, "Major" is only for issues in Needs Review state that haven't gotten a review in at least 2 weeks. See https://www.drupal.org/node/539608#application-priorities

kscheirer’s picture

Status: Reviewed & tested by the community » Needs work

Blocking issues

  1. Remove LICENSE.txt, the drupal.org packaging script will include all necessary licensing information.

I saw sure there was a module that did this or something similar, but I can't actually find any, so no duplication worries. I did not find any other issues. There's a few minor points listed at http://pareview.sh/pareview/httpgitdrupalorgsandboxmredding2294099git.

uberhacker’s picture

Hey Karl,

The PAReview was from back in August. Please make sure you review the latest code. Here are the results from a recent code sniff:

FILE: ./field_embed/README.txt
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
25 | WARNING | Line exceeds 80 characters; contains 89 characters
----------------------------------------------------------------------

Please do not let simple things like removing LICENSE.txt hold this back.

Thanks

uberhacker’s picture

Status: Needs work » Reviewed & tested by the community
uberhacker’s picture

Adding patch to remove LICENSE.txt

stBorchert’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

How is this module different from Token Insert or Token Insert Entity.
Please outline the differences (if there are any) in your project page and explain (if there are only a few) why its better to not provide the additional feature as a patch to said modules.

uberhacker’s picture

Hi Stefan,
Thank you for noticing and that is a very good question. The token modules you mention perform the same task but are different in their implementation. This module works as a text format filter rather than using token replacement. But it might be better to ask if this project is more similar to Entity Embed. See https://www.drupal.org/project/entity_embed.

PA robot’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Closing due to lack of activity. If you are still working on this application, you should fix all known problems and then set the status to "Needs review". (See also the project application workflow).

I'm a robot and this is an automated message from Project Applications Scraper.