I think _webform_theme_component() needs updating. The sample here:
http://drupalcontrib.org/api/drupal/contributions!webform!webform.api.ph...

Is quite different from what I'm finding in the code. There's an example of it's use here:
http://drupal.org/node/435232#comment-4829158

But think it needs the file reference as per:

/**
* Implements _webform_theme_component().
*/
function _webform_theme_number() {
  return array(
    'webform_number' => array(
      'render element' => 'element',
      'file' => 'components/number.inc',
    ),
    'webform_display_number' => array(
      'render element' => 'element',
      'file' => 'components/number.inc',
    ),
  );
}

If not some more docs would help.

Files: 
CommentFileSizeAuthor
#3 webform_update_theme_component.patch602 bytesquicksketch

Comments

Thanks you're right. The documentation hasn't been updated for Drupal 7 and still reflects the D6 syntax.

Ok, so thought I'd post some examples as I was still a bit lost. These are all from webform related modules:

webform_node_element example:

function _webform_theme_node() {
  return array(
    'webform_node_element_node' => array(
      'render element' => 'element',
    ),
    'webform_display_node' => array(
      'render element' => 'element',
    ),
  );
}

webform_table_element:

function _webform_theme_table_element() {
  return array(
    'table_element' => array(
      'render element' => 'element',
    ),
    'table_element_row' => array(
      'render element' => 'element',
    ),
  );
}

webform_simplenews:

function _webform_theme_newsletter_email() {
  return array(
    'webform_display_newsletter_email' => array(
      'render element' => 'element',
    ),
  );
}

webform_paypal:

function _webform_theme_paypal() {
  return array(
    'webform_display_paypal' => array(
      'render element' => 'element',
    ),
  );
}

webform_mailchimp:

function _webform_theme_mailchimp() {
  return array(
    'webform_display_mailchimp' => array(
      'render element' => 'element',
    ),
  );
}

webform_html_textarea:

function _webform_theme_html_textarea() {
  return array(
    'webform_display_html_textarea' => array(
      'render element' => 'element',
    ),
  );
}

webform_draggable_list:

function _webform_theme_draggable_list() {
  return array(
    'draggable_list' => array(
      'render element' => 'element',
    ),
  );
}

webform_ajax_page:

function _webform_theme_ajax_page() {
  return array(
    'ajax_page' => array(
      'render element' => 'element',
    ),
  );
}

Status:Active» Fixed
StatusFileSize
new602 bytes

Thanks. For starters I just updated the example code copied from grid.inc.

Ok, but for modules like uc_webform (which I've been working on bringing to D7), you can't use something like:
'file' => 'components/product.inc',

That line looks for the file within the webform/components directory and not the uc_webform/components directory.

None of the working examples (outside of the main module) use the file line. So I'm still confused here.

Hm, yeah I suppose we can be more specific. By using hook_theme()'s "theme path", you can make the 'file' property be relative to a different module.

Status:Fixed» Active

I'm trying to work on a module that works with both Ubercart & Webform so it could well be a bit more confusing. However in reading the docs:
http://api.drupal.org/api/drupal/modules!system!system.api.php/function/...

It doesn't really look like I should need to use "theme path" because I'm trying to reference a file within uc_webform's directory.

This file path has also been defined in function uc_webform_webform_component_info() - which is in the uc_webform.module file as well as in the component/product.inc file's function _webform_theme_product().

Seems particularly redundant in the latter case as it's defining the actual file itself.

Anyways, would love some more direction on best practices for using Webform's API.

The errors generated are this:

Warning: include_once(/home/dm7/sites/all/modules/contrib/webform/components/product.inc) [function.include-once]: failed to open stream: No such file or directory in theme() (line 966 of /home/dm7/includes/theme.inc).
Warning: include_once() [function.include]: Failed opening '/home/dm7/sites/all/modules/contrib/webform/components/product.inc' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in theme() (line 966 of /home/dm7/includes/theme.inc).

Where the uc_webform module isn't even in sites/all but rather in a site-specific modules folder. I am also confused as to what to change and how to get Drupal to look in the correct place for product.inc (.../sites/SITE/modules/uc_webform/components/product.inc).

Just posting a related issue here #1255832: Drupal 7? with some other errors & efforts to deal with the components.

@quicksketch - any thoughts on best practice documentatation for Webform's API?

Maybe there are other successful implementations by now to draw on.

How much of the documentation will need to change between versions 3 & 4?

@mgifford: Isn't just the inadequacy of the documentation the problem here, rather than the method by which we're documenting? I don't have any problems with our approach of using webform.api.php to document things.

The documentation between 3 and 4 right now is pretty much 95% the same, but I expect by the final release it may be more like 75% the same.

Status:Active» Postponed

Ok, so all webform documentation is inline in the code as per:
http://drupalcontrib.org/api/drupal/contributions!webform!webform.api.php/7
http://drupalcontrib.org/api/drupal/contributions!webform!webform.api.ph...

If anyone wants any other documentation, anyone should feel free to take what's there and bring it into a handbook page within:
http://drupal.org/documentation/modules/webform

Mind you in the git version of the 4.x code, the webform_component seems to now comes from webform_hooks.php if I'm looking for the docs on: _webform_theme_component(), it's pretty sparse.


hook_theme()
's got lots of definition for generic implementations. I think I should be able to use:

'file' => drupal_get_path('module', 'uc_webform') . '/components/product.inc'),

I'll try to verify this and close it shortly.

If anyone wants any other documentation, anyone should feel free to take what's there and bring it into a handbook page within:
http://drupal.org/documentation/modules/webform

I personally try to avoid much in-depth documentation of hooks in the handbook because versioning handbook pages is difficult. The documentation for 6.x-2.x, 6.x-3.x, 7.x-3.x, 7.x-4.x, etc is all different, though *mostly* the same as I said, there are important differences. It makes sense to keep the documentation as part of the code so they can be maintained at the same time. I usually use the handbook for front-end documentation or tutorials.

I tried

'file' => drupal_get_path('module', 'uc_webform') . '/components/product.inc'),

and can verify that the above code works to get rid of those errors.

The solution in #11 did not solve the error for me, but adding the 'path' => drupal_get_path('module', 'mymodule'), line to all my definitions in _webform_theme_component() implementation did.