Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By implementing hook_field_formatter_settings_form() and providing a default setting of 'text' => 'Contact person by email' in email_field_formatter_info().
Comment | File | Size | Author |
---|---|---|---|
#29 | edit_link_and_title_text-1346102-29.patch | 7.46 KB | MiroslavBanov |
#24 | email.module.txt | 21.38 KB | capfive |
#19 | edit_link_and_title_text-1346102-19.patch | 7.59 KB | MiroslavBanov |
#17 | edit_link_and_title_text-1346102-17-d7.patch | 7.56 KB | redndahead |
#12 | edit_link_and_title_text-1346102-12.patch | 7.39 KB | boyan.borisov |
Comments
Comment #1
BWPanda CreditAttribution: BWPanda commentedThis patch seems to do the trick, but someone should check to make sure I implemented the suggested method correctly...
Comment #2
Dave ReidIt would be good if we could also run $settings['text'] through token_replace() using $data[$object_type] = $object.
Comment #3
BWPanda CreditAttribution: BWPanda commentedGood idea!
I also added the ability to change the email form's title (also using token replacement).
Some possible issues:
Review away!
Comment #4
ethnovode CreditAttribution: ethnovode commentedThank you!
I was able to change the link using tokens. The form title didn't change but it could be because I use the Display Suite module.
Comment #5
broonI applied the patch to the latest stable version (7.x-1.1) and it works like a charm.
I also have Display suite installed and couldn't find an error so far.
Just for clarification (for new users): On manage display page for a content type you are able to set link text and form title. Save the settings and it works without clearing cache. If you do not change the settings the link in content will disappear due to
$settings['text']
not set.Comment #6
BWPanda CreditAttribution: BWPanda commentedHere's an update to the patch in #3 that disables the sanitation of the Email form title (I had set the form title to 'Email [node:title]' and as my node's title was
O'Meara Wood & Associates
, my form title displayed asEmail O'Meara Wood & Associates
).Comment #7
oneidprod CreditAttribution: oneidprod commentedThanks for your work on this as it was exactly what i was looking for. I applied the patch in #6 to the latest stable version 7.x-1.2 as well as the latest dev version 7.x-1.x-dev and the "Link Text" worked as designed, but the "Form Title" never changed regardless of any token that i tried. I also tried the patch in #3 on 7.x-1.2 and got the same results. I have display suite installed but not using for this content type, but went ahead and disabled it and it didn't matter, same results.
After having the cache clear itself, i noticed that the Email Contact Form Title goes away completely when using this patch. The
<h1 id="page-title" class="title">Email Contact Form</h1>
isn't even there anymore. So I don't think that it is so much that it's not changing the title as it is just being removed all together and because it was still cached I was still seeing the default title.I'm not a coder, but I can test anything you want to try if you get time.
Comment #8
jlongbottom CreditAttribution: jlongbottom commentedPatch in #6 is great, but only works for default display type. I am showing an email field that is coming from a custom display type (using display suite) or a Teaser, so this fails because the module hard-codes the settings to come from the default display type. Not sure what the best solution is. I guess it could loop through each display type until it finds one with data in the 'settings' element.
We get the field info in
email_contact_form_title
:Here is a dump of $field:
EDIT:
Ok, so looping through worked out ok. Too lazy to make a patch, so here is the whole, updated function:
Comment #9
fearlsgroove CreditAttribution: fearlsgroove commentedUsing the default display for settings is a bummer. Here's a modified approach:
Comment #10
fearlsgroove CreditAttribution: fearlsgroove commentedSorry that last patch was crap. Beyond the syntax error, there's also a problem where if the formatter is not configured for the field, it returns not found when trying to just visit the URL.
Here's another attempt that adds an instance setting to allow the form to be used without a formatter being configured. Maybe this should be a permission instead? I'm not sure what the logic behind restricting the email form page to a configured field might be. Security I assume?
Comment #11
realityloopworks for me. Thanks.
Comment #12
boyan.borisov CreditAttribution: boyan.borisov commentedThe last patch works fine but I am uploading a new one just put the text in t() function in order to be translatable.
Comment #13
mh86 CreditAttribution: mh86 commentedThanks to all for the work on this issue. I was just taking a look at the last patch, and have a few notes:
t with dynamic text ($settings['text']) is not recommended. As far as I know we should rather take a look at i18n(_field) for such use cases.
Furthermore, token_replace() sanitizes the text by default, the same as l() does, so I think we have a double escaping here
Not really sure if we need a separate formatter, you could directly do it in views on your own (url rewriting with token replacements)
We should have a fallback to the default title, if the form_title is not yet set (on updating the website, this setting will be empty).
Again, this setting will be empty on updating the module/website
Comment #14
bisonbleu CreditAttribution: bisonbleu commented[updated]
Patch in #12 works as designed.
I had an issue in Views when the email field was using a relationship.
But it was no more than a bad configuration on my part.
So disregard the attached export.
Cheers : )
Comment #15
joeyenglish CreditAttribution: joeyenglish commentedAwesome solution. Question is, where is this changed? I can't seem to find the way to edit the field, as it still says "Contact person by email."
Comment #16
bisonbleu CreditAttribution: bisonbleu commented@joeyenglish, after applying the patch, go to the Manage Fields tab of your content type and edit your email field (e.g. admin/structure/types/manage/[name_of_your_content_type]/fields/name_of_your_email_field). In the field settings, look for the form field Email form title.
Comment #17
redndahead CreditAttribution: redndahead commentedThis version incorporates items 1a and 4 from #13. It also adds a special case for taxonomies that have a contact field. That caused the error:
Notice: Undefined property: stdClass::$type in email_contact_form_title() (line 384
Comment #18
realityloopJust wondering if there is there any reason you use double quotes here instead of single with escaping like you have with the other instances of t()? I think it may be better to change that, otherwise this looks good to me.
Comment #19
MiroslavBanov CreditAttribution: MiroslavBanov commentedThe version in #17 removes the t() and doesn't add any i18n handling either.
Here is a patch with the t() back, and also with tokens in popup (Node tokens tree kill my browser).
Comment #20
umakart CreditAttribution: umakart commented#19 works for me. Thanks a lot. Why not committing?
Comment #21
MiroslavBanov CreditAttribution: MiroslavBanov commentedNeeds review before committing. Also note that #18 is not addressed.
Comment #22
fearlsgroove CreditAttribution: fearlsgroove commented@MiroslavBanov -- you can't use t() on user provided values, only hard coded values. See docs for
t()
for details. I don't know what the right way to handle i18n is here as i'm not translation expert, but that bit shouldn't be committed.Comment #23
MiroslavBanov CreditAttribution: MiroslavBanov commentedRight. Then I guess it needs work.
Comment #24
capfive CreditAttribution: capfive commentedcouldn't apply this so i applied it manually... to 7.x-1.3 here is the .txt file :)
p.s it is working very well!
Comment #25
capfive CreditAttribution: capfive commented***UPDATE!!!!*** Not playing nice with paragraphs bundle
i added the field to a paragraph bundle for a team display and receive the following error pops up on the form page, but the form does send.
here is the line that i put in.
with
$bundle_name = $entity[$object_id]->type;
being on line 383.Thanks!
Comment #26
MiroslavBanov CreditAttribution: MiroslavBanov commented@capfive
Should be replaced with something like
Comment #27
capfive CreditAttribution: capfive commented@MiroslavBanov
got some other issues when replacing that code
happy to keep testing for you if you would like to have another go at it :)
Comment #28
MiroslavBanov CreditAttribution: MiroslavBanov commented@capfive
OK, here's the corrected code
Comment #29
MiroslavBanov CreditAttribution: MiroslavBanov commentedNow I finally had to fix this for field collection item - here is the patch. #22 is still not fixed though.