You are here

function hook_webform_component_info in Webform 7.4

Same name and namespace in other branches
  1. 6.3 webform.api.php \hook_webform_component_info()
  2. 7.3 webform.api.php \hook_webform_component_info()

Define components to Webform.

Return value

array An array of components, keyed by machine name. Required properties are "label" and "description". The "features" array defines which capabilities the component has, such as being displayed in e-mails or csv downloads. A component like "markup" for example would not show in these locations. The possible features of a component include:

  • csv
  • email
  • email_address
  • email_name
  • required
  • conditional
  • spam_analysis
  • group
  • private

Note that most of these features do not indicate the default state, but determine if the component can have this property at all. Setting "required" to TRUE does not mean that a component's fields will always be required, but instead give the option to the administrator to choose the requiredness. See the example implementation for details on how these features may be set.

An optional "file" may be specified to be loaded when the component is needed. A set of callbacks will be established based on the name of the component. All components follow the pattern:

_webform_[callback]_[component]

Where [component] is the name of the key of the component and [callback] is any of the following:

  • defaults
  • edit
  • render
  • display
  • submit
  • delete
  • help
  • theme
  • analysis
  • table
  • csv_headers
  • csv_data

See the sample component implementation for details on each one of these callbacks.

See also

webform_components()

Related topics

1 function implements hook_webform_component_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

webform_webform_component_info in ./webform.module
Implements hook_webform_component_info().
1 invocation of hook_webform_component_info()
webform_components in ./webform.module
Get a list of all available component definitions.

File

./webform.api.php, line 485
Sample hooks demonstrating usage in Webform.

Code

function hook_webform_component_info() {
  $components = array();
  $components['textfield'] = array(
    'label' => t('Textfield'),
    'description' => t('Basic textfield type.'),
    'features' => array(
      // This component includes an analysis callback. Defaults to TRUE.
      'analysis' => TRUE,
      // Add content to CSV downloads. Defaults to TRUE.
      'csv' => TRUE,
      // This component supports default values. Defaults to TRUE.
      'default_value' => FALSE,
      // This component supports a description field. Defaults to TRUE.
      'description' => FALSE,
      // Show this component in e-mailed submissions. Defaults to TRUE.
      'email' => TRUE,
      // Allow this component to be used as an e-mail FROM or TO address.
      // Defaults to FALSE.
      'email_address' => FALSE,
      // Allow this component to be used as an e-mail SUBJECT or FROM name.
      // Defaults to FALSE.
      'email_name' => TRUE,
      // This component may be toggled as required or not. Defaults to TRUE.
      'required' => TRUE,
      // Store data in database. Defaults to TRUE. When FALSE, submission data
      // will never be saved. This is for components like fieldset, markup, and
      // pagebreak which do not collect data.
      'stores_data' => TRUE,
      // This component supports a title attribute. Defaults to TRUE.
      'title' => FALSE,
      // This component has a title that can be toggled as displayed or not.
      'title_display' => TRUE,
      // This component has a title that can be displayed inline.
      'title_inline' => TRUE,
      // If this component can be used as a conditional SOURCE. All components
      // may always be displayed conditionally, regardless of this setting.
      // Defaults to TRUE.
      'conditional' => TRUE,
      // If this component allows other components to be grouped within it
      // (like a fieldset or tabs). Defaults to FALSE.
      'group' => FALSE,
      // If this component can be used for SPAM analysis.
      'spam_analysis' => FALSE,
      // If this component saves a file that can be used as an e-mail
      // attachment. Defaults to FALSE.
      'attachment' => FALSE,
      // If this component reflects a time range and should use labels such as
      // "Before" and "After" when exposed as filters in Views module.
      'views_range' => FALSE,
      // Set this to FALSE if this component cannot be used as a private
      // component. If this is not FALSE, in your implementation of
      // _webform_defaults_COMPONENT(), set ['extra']['private'] property to
      // TRUE or FALSE.
      'private' => FALSE,
    ),
    // Specify the conditional behaviour of this component.
    // Examples are 'string', 'date', 'time', 'numeric', 'select'.
    // Defaults to 'string'.
    'conditional_type' => 'string',
    'file' => 'components/textfield.inc',
  );
  return $components;
}