The image field named: field_events_foto. Default insert style: Original image.

I copy to my themes the files insert-image.tpl.php - module(insert) sees it.
I rename ant try to use insert-image--field-events-foto.tpl.php, image-insert-image--field-events-foto.tpl.php - module does not see all them :(.
The cache is cleared each time. Where's the problem?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Title: The insert does not see my template » Provide per-field template suggestions
Category: bug » feature

Insert module does not provide per-field template suggestions (though that's a good feature request, which is where I've moved this). It only provides per image-style suggestions. So you can have templates like image-insert-image--thumbnail.tpl.php or image-insert-image--large.tpl.php.

For the insert-image.tpl.php we don't provide any suggestions at all. I think making those by field name sounds like a good idea. Are you using an image preset with your example or just trying to insert the original image?

jack-pl’s picture

So you can have templates like image-insert-image--thumbnail.tpl.php or image-insert-image--large.tpl.php

I copied image-insert-image.tpl.php file from module templates directory and paste to mytheme/templates, but it's not working.

I've tried also:

image-insert-image--thumbnail.tpl.php
image-insert-image--large.tpl.php
insert-image.tpl.php

these files aren't working either.. The cache is cleared. Tested on clean installation of Drupal 7.22

jordi_bcktt’s picture

I have exactly the same problem

boshtian’s picture

Same problem here.

Image style name is content_image, my template name is image-insert-image--content-image.tpl but it's not working.

boshtian’s picture

As soon as I published comment, I realized what I'm doing wrong.

If you're using admin theme, the template files must be in there, because you use that template when editing content.

mesch’s picture

Issue summary: View changes

+1 for this feature. Perhaps it would be sufficient to add in helpful variables to the template preprocessors that would allow everyone to create their own theme hook suggestions. I can see the following as being especially useful:

- field name
- entity type
- entity bundle

mesch’s picture

In case it's of use to anyone else out there, here is how I applied markdown templates I created to one content type only. It's obviously a bit of a hack, but a functional hack nonetheless.

/**
 * Implements hook_form_FORM_ID_alter() for [type]_node_form
 */
function [theme]_form_[type]_node_form_alter(&$form, &$form_state) {
  // Flag the form for the insert template preprocessors
  // Note this hook is invoked before the #after_build function insert_element_process()
  $markdown = &drupal_static(__FUNCTION__, TRUE);
}

/**
 * Implements hook_preprocess_HOOK() for insert_image
 * Repeat for each template type you're overriding
 */
function [theme]_preprocess_insert_image(&$variables) {
  $markdown = &drupal_static('[theme]_form_[type]_node_form_alter');
  if (isset($markdown)) {
    // Do any necessary preprocessing for your own markdown templates
    
    ...

    // Make sure your mardown template is used
    $variables['theme_hook_suggestion'] = $variables['theme_hook_original'] . '__markdown';
  }
}

Snater’s picture

Assigned: Unassigned » Snater
Status: Active » Needs review
Parent issue: » #2981038: Release 8.x-2.0
FileSize
2.46 KB

Browsing though old tickets while working on the module's D8 version. This ticket is quite reasonable. I have attached a change set that should implement template suggestions by field name. I briefly tested it. It is a bit hacky, because hook_insert_element is simply extended with $element. I do not see a major reason, why not to pass $element (it would, of course, also be possible to just pass $element['#field_name']), but the function signature could be a bit cleaner. However, shuffling parameters would require a new major version of Insert for Drupal 7 (7.x-2.0), which I do not see happening any more.

I will implement additional template suggestions in the D8 version as well.

  • Snater committed b43a719 on 7.x-1.x
    Issue #1803096: Per-field template suggestions
    
Snater’s picture

Version: 7.x-1.x-dev » 8.x-2.x-dev
Status: Needs review » Active

  • Snater committed 2f42d56 on 8.x-2.x
    Issue #1803096: Per-field template suggestions
    
Snater’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

joelpittet’s picture

@Snator

I ran into a fatal error due to this change, not totally sure if I should post here or fix multiupload_filefield_widget so I'll do both. #3403905: ArgumentCountError: Too few arguments to function image_insert_content(), 3 passed in multiupload_imagefield_widget/multiupload_imagefield_widget.module

ArgumentCountError: Too few arguments to function image_insert_content(), 3 passed in multiupload_imagefield_widget/multiupload_imagefield_widget.module on line 125 and exactly 4 expected in image_insert_content() (line 42 of insert/includes/image.inc).
The website encountered an unexpected error. Please try again later.

joelpittet’s picture

Don't get me wrong, I appreciate the new life you've given to this module, keep up the good work!