I was trying to 'borrow' some themeing code from your date component for use on a form of my own. I tried to do so by setting '#theme' = 'webform_date' on the lement. However this lead me to discover that the file (date.inc) is not loaded when the theme('webform_date', ...) function was called.

Probably no problem in your own code, but for external code it might be. The solution is to add a 'file => '...' entry to each function-based theme hook defined in one of the component includes. Example:

file: components/date.inc

function _webform_theme_date() {
  return array(
    'webform_date' => array(
      'render element' => 'element',
      'file' => 'components/date.inc',  // add this line everywhere
    ),
    ...

Comments

quicksketch’s picture

Priority: Normal » Minor

I ran across this the other day too. We definitely should do this for all our components that define theme functions. Right now it's not causing any trouble though (since the component file is always pulled in first anyway, since otherwise it wouldn't have a form element to render in the first place), but for "correctness" it would be a good idea.

fietserwin’s picture

You're right. I filed this issue when I had not completely sorted out how to hook into/borrow your code. Now that I have, the problem should not appear anymore.

How to get a webform component element into your own form:

  // Borrow the date picker from Webform
  $component = array(
    'name' => 'Arrival date',
    'type' => 'date',
    'value' => 'today',
    'extra' => array(
      'timezone' => 'user',
      'title_display' => 'inline',
      'datepicker' => 1,
      'year_textfield' => 0,
      'year_start' => '+0',
      'year_end' => '+2',
      'description' => '',
    ),
    'mandatory' => 0,
    'weight' => 3,
  );
  $form['arrival'] = webform_component_invoke($component['type'], 'render', $component, NULL, TRUE);
  $form['arrival']['#parents'] = array('dummy', 'arrival');

  // Attach necessary JavaScript and CSS.
  $form['#attached']['css'][] = drupal_get_path('module', 'webform') . '/css/webform.css';
  $form['#attached']['js'][] = drupal_get_path('module', 'webform') . '/js/webform.js';
amateescu’s picture

Status: Active » Needs review
StatusFileSize
new4.11 KB

Patch attached.

quicksketch’s picture

Status: Needs review » Fixed

Thanks, I rolled this patch for Drupal 6 to match. Committed your patch to D7 and pushed both to Git.

quicksketch’s picture

StatusFileSize
new4.3 KB

Here's the D6 patch I meant to attach to the last post.

Status: Fixed » Closed (fixed)

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