I created an additional settings page that lets the administrator select the default template for each content type. I was able to use this to set up RSVPs for Events.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rv0’s picture

Title: Default Template for each content type » Source type and default Template per content type
Status: Needs review » Needs work

Patch has some coding style issues

} else {

is one of them

Ideally I would love to have a matrix style config that allows you to set one or more source types per destination type

S/D                 Page       Event      Contact           | Default
Page                 x             x                                 | >select
Event                               x                                 | >select
Contact            x                                x               | >select

(sorry , formatting will probably be ruined)
So setting this to needs work as it doesn't really have any use committing this when it will have to be rewritten later on.

abtm’s picture

Just realised that I need the "template" or "default" feature for the webform module and went across #1689434: Six overlapping modules. Decided to try webform_template. After enabling the module and making the settings, I have two template options in the node (destination) creating form. (As I have only created two webform nodes.) I am wondering when I have 100 nodes of this type, when creating the 101st node would I have 100 template options in the select box?

rv0’s picture

@abtm
This seems only slightly on topic to this feature request.
Use a "template only" content type or custom coding (hook_form_alter) for your usecase.
Please create a seperate issue if you need more help with this, this is out of scope for this issue.

SGhosh’s picture

Thanks a lot for the patch. I am using version 7.x-1.2. Works awesome with a few minor changes -

includes/webform_template.admin.inc

-    $form['webform_template_default_' . $type] = array(
+    $form['webform_template_default' ] = array(



webform_template.module

function webform_template_form_node_form_alter(&$form, &$form_state, $form_id) {
  $tpl_src = array_filter(variable_get('webform_template_src', array()));
  $tpl_dest = array_filter(variable_get('webform_template_dest', array()));
 
   if (isset($tpl_dest[$form['type']['#value']]) && !empty($tpl_src)) {
+    $show_lang = variable_get('webform_template_lang');
+    $result = db_query('SELECT nid,title,language FROM {node} WHERE type IN (:types) AND status = 1 ORDER BY tnid', array(':types' => $tpl_src));
+
+    $templates[] = '- ' . t('none') . ' -';
+    foreach ($result as $row) {
+      $templates[$row->nid] = $row->title;
+      if (!empty($show_lang)) {
+        $templates[$row->nid] .= ' [' . $row->language . ']';
+      }
+    }
...
...
     $form['webform_template']['source'] = array(
       '#type' => 'select',
       '#title' => t('Templates'),
-      '#options' => _webform_template_templates($tpl_src, $tpl_dest),
+      '#options' => $templates,
 
 /**
- * Helper function gets the available templates for the source's #options attribute.
- */
-function _webform_template_templates($tpl_src, $tpl_dest) {
-  $show_lang = variable_get('webform_template_lang');
-  $result = db_query('SELECT nid,title,language FROM {node} WHERE type IN (:types) AND status = 1 ORDER BY tnid', array(':types' => $tpl_src));
-
-  $templates[] = '- ' . t('none') . ' -';
-  foreach ($result as $row) {
-    $templates[$row->nid] = $row->title;
-    if (!empty($show_lang)) {
-      $templates[$row->nid] .= ' [' . $row->language . ']';
-    }
-  }
-  
-  return $templates;
-}
-

rv0’s picture

@SGhosh
Why are you removing that function?
And please, use patch files instead of manually inserting large texts in the issue queue

SGhosh’s picture

@rv0
yep sorry about that. I found out later that function is being called somewhere else too.

And about not submitting a patch, following how patches area created for drupal modules I was supposed to first clone the project, however I didn't find one for version 7.x-1.2 so went ahead and pasted the code here. Will be more careful from next time though. Thanks.

rv0’s picture

@SGhosh
When writing patches always use latest dev. http://drupal.org/project/webform_template/git-instructions
Always provide some explanation about what and why you changed things.

In any case, this patch wont make it for the reasons stated earlier (grid approach)

rv0’s picture

Issue summary: View changes

grammar

SocialNicheGuru’s picture

Issue summary: View changes

the patch no longer applies cleanly to Sept 15, 2015 - 7.x-4.0 version.
https://www.drupal.org/node/2568943

xumepadismal’s picture

Version: 7.x-1.x-dev » 7.x-4.x-dev
Status: Needs work » Needs review
FileSize
10.24 KB

I think we need to switch to the recommended channel…
This patch is an attempt to address #1. Clear caches is required after patching. Please review