Révision b0dc3a2e
Ajouté par Julien Enselme il y a plus de 7 ans
drupal7/modules/system/system.api.php | ||
---|---|---|
1797 | 1797 |
* the $form_id input matched your module's format for dynamically-generated |
1798 | 1798 |
* form IDs, and if so, act appropriately. |
1799 | 1799 |
* |
1800 |
* Third, forms defined in classes can be defined this way. |
|
1801 |
* |
|
1800 | 1802 |
* @param $form_id |
1801 | 1803 |
* The unique string identifying the desired form. |
1802 | 1804 |
* @param $args |
... | ... | |
1807 | 1809 |
* @return |
1808 | 1810 |
* An associative array whose keys define form_ids and whose values are an |
1809 | 1811 |
* associative array defining the following keys: |
1810 |
* - callback: The name of the form builder function to invoke. This will be |
|
1811 |
* used for the base form ID, for example, to target a base form using |
|
1812 |
* hook_form_BASE_FORM_ID_alter(). |
|
1812 |
* - callback: The callable returning the form array. If it is the name of |
|
1813 |
* the form builder function then this will be used for the base |
|
1814 |
* form ID, for example, to target a base form using |
|
1815 |
* hook_form_BASE_FORM_ID_alter(). Otherwise use the base_form_id key to |
|
1816 |
* define the base form ID. |
|
1813 | 1817 |
* - callback arguments: (optional) Additional arguments to pass to the |
1814 | 1818 |
* function defined in 'callback', which are prepended to $args. |
1815 |
* - wrapper_callback: (optional) The name of a form builder function to |
|
1816 |
* invoke before the form builder defined in 'callback' is invoked. This |
|
1817 |
* wrapper callback may prepopulate the $form array with form elements, |
|
1818 |
* which will then be already contained in the $form that is passed on to |
|
1819 |
* the form builder defined in 'callback'. For example, a wrapper callback |
|
1820 |
* could setup wizard-alike form buttons that are the same for a variety of |
|
1821 |
* forms that belong to the wizard, which all share the same wrapper |
|
1822 |
* callback. |
|
1819 |
* - base_form_id: The base form ID can be specified explicitly. This is |
|
1820 |
* required when callback is not the name of a function. |
|
1821 |
* - wrapper_callback: (optional) Any callable to invoke before the form |
|
1822 |
* builder defined in 'callback' is invoked. This wrapper callback may |
|
1823 |
* prepopulate the $form array with form elements, which will then be |
|
1824 |
* already contained in the $form that is passed on to the form builder |
|
1825 |
* defined in 'callback'. For example, a wrapper callback could setup |
|
1826 |
* wizard-like form buttons that are the same for a variety of forms that |
|
1827 |
* belong to the wizard, which all share the same wrapper callback. |
|
1823 | 1828 |
*/ |
1824 | 1829 |
function hook_forms($form_id, $args) { |
1825 | 1830 |
// Simply reroute the (non-existing) $form_id 'mymodule_first_form' to |
... | ... | |
1843 | 1848 |
'wrapper_callback' => 'mymodule_main_form_wrapper', |
1844 | 1849 |
); |
1845 | 1850 |
|
1851 |
// Build a form with a static class callback. |
|
1852 |
$forms['mymodule_class_generated_form'] = array( |
|
1853 |
// This will call: MyClass::generateMainForm(). |
|
1854 |
'callback' => array('MyClass', 'generateMainForm'), |
|
1855 |
// The base_form_id is required when the callback is a static function in |
|
1856 |
// a class. This can also be used to keep newer code backwards compatible. |
|
1857 |
'base_form_id' => 'mymodule_main_form', |
|
1858 |
); |
|
1859 |
|
|
1846 | 1860 |
return $forms; |
1847 | 1861 |
} |
1848 | 1862 |
|
Formats disponibles : Unified diff
Update to Drupal 7.52