function form_load_include

Ensures an include file is loaded whenever the form is processed.

Example:

// Load node.admin.inc from Node module.
form_load_include($form_state, 'inc', 'node', 'node.admin');

Use this function instead of module_load_include() from inside a form constructor or any form processing logic as it ensures that the include file is loaded whenever the form is processed. In contrast to using module_load_include() directly, form_load_include() makes sure the include file is correctly loaded also if the form is cached.

Parameters

$form_state: The current state of the form.

$type: The include file's type (file extension).

$module: The module to which the include file belongs.

$name: (optional) The base file name (without the $type extension). If omitted, $module is used; i.e., resulting in "$module.$type" by default.

Return value

The filepath of the loaded include file, or FALSE if the include file was not found or has been loaded already.

See also

module_load_include()

Related topics

10 calls to form_load_include()
AccountSettingsForm::buildForm in drupal/core/modules/user/lib/Drupal/user/AccountSettingsForm.php
Implements \Drupal\Core\Form\FormInterface::buildForm().
DateFormatAddForm::buildForm in drupal/core/modules/system/lib/Drupal/system/Form/DateFormatAddForm.php
Form constructor.
DateFormatEditForm::buildForm in drupal/core/modules/system/lib/Drupal/system/Form/DateFormatEditForm.php
Form constructor.
FieldDeleteForm::submitForm in drupal/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php
Form submission handler.
FieldEditForm::buildForm in drupal/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php
Form constructor.

... See full list

File

drupal/core/includes/form.inc, line 644
Functions for form and batch generation and processing.

Code

function form_load_include(&$form_state, $type, $module, $name = NULL) {
  if (!isset($name)) {
    $name = $module;
  }
  if (!isset($form_state['build_info']['files']["{$module}:{$name}.{$type}"])) {

    // Only add successfully included files to the form state.
    if ($result = module_load_include($type, $module, $name)) {
      $form_state['build_info']['files']["{$module}:{$name}.{$type}"] = array(
        'type' => $type,
        'module' => $module,
        'name' => $name,
      );
      return $result;
    }
  }
  return FALSE;
}