Revision 14feebe9
Added by Andreas Kohlbecker over 11 years ago
7.x/modules/cdm_dataportal/settings.php | ||
---|---|---|
1701 | 1701 |
/** |
1702 | 1702 |
* Implements hook_element_info(). |
1703 | 1703 |
* |
1704 |
* @see http://drupal.org/node/37862 |
|
1704 |
* Allows modules to declare their own Form API element types and specify their default values. |
|
1705 |
* |
|
1706 |
* @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_element_info/7 |
|
1705 | 1707 |
*/ |
1706 | 1708 |
function cdm_dataportal_element_info() { |
1707 | 1709 |
$type['checkboxes_preferred'] = array( |
1708 | 1710 |
'#input' => TRUE, |
1709 |
'#process' => array('expand_checkboxes_preferred'),
|
|
1711 |
'#process' => array('checkboxes_preferred_expand'),
|
|
1710 | 1712 |
'#after_build' => array('checkboxes_preferred_after_build'), |
1711 | 1713 |
'#theme' => array('checkboxes_preferred'), |
1712 | 1714 |
// '#theme_wrapper' => array('form_element'), |
... | ... | |
1715 | 1717 |
} |
1716 | 1718 |
|
1717 | 1719 |
/** |
1718 |
* #process function for the custom form element type 'checkbox_preferred' |
|
1720 |
* #process callback function for the custom form element type 'checkbox_preferred' |
|
1721 |
* |
|
1722 |
* |
|
1719 | 1723 |
*/ |
1720 |
function expand_checkboxes_preferred($element, &$form_state, $form) { |
|
1721 |
// First of all create the checkboxes. |
|
1724 |
function checkboxes_preferred_expand($element, &$form_state, $form) { |
|
1725 |
|
|
1726 |
// First of all create checkboxes for each of the elements |
|
1722 | 1727 |
$element = form_process_checkboxes($element); |
1723 | 1728 |
|
1724 | 1729 |
$children = element_children($element); |
... | ... | |
1728 | 1733 |
'#weight' => -1, |
1729 | 1734 |
); |
1730 | 1735 |
|
1736 |
// prepare first part each of the table rows which contains the row label |
|
1731 | 1737 |
$weight = 0; |
1732 | 1738 |
foreach ($children as $key) { |
1733 | 1739 |
$odd_even = $weight % 4 == 0 ? 'odd' : 'even'; |
... | ... | |
1739 | 1745 |
} |
1740 | 1746 |
$weight = 0; |
1741 | 1747 |
|
1748 |
// add a radio button to each of the checkboxes, the |
|
1749 |
// check boxes have already been created at the beginning |
|
1750 |
// of this function |
|
1742 | 1751 |
if (count($element['#options']) > 0) { |
1743 | 1752 |
foreach ($element['#options'] as $key => $choice) { |
1744 | 1753 |
if (!isset($element[$key . '_preferred'])) { |
... | ... | |
1750 | 1759 |
'#attributes' => $element['#attributes'], |
1751 | 1760 |
// '#spawned' => TRUE, |
1752 | 1761 |
'#weight' => $weight + 1, |
1753 |
'#prefix' => '<td>', |
|
1754 |
'#suffix' => '</td></tr>', |
|
1762 |
'#prefix' => '<td>', // add a prefix to start a new table cell
|
|
1763 |
'#suffix' => '</td></tr>', // add a prefix to close the tabel row
|
|
1755 | 1764 |
); |
1756 | 1765 |
} |
1757 | 1766 |
$weight += 2; |
1758 | 1767 |
} |
1759 | 1768 |
} |
1760 | 1769 |
|
1770 |
// end the table |
|
1761 | 1771 |
$element['table_end'] = array( |
1762 | 1772 |
'#markup' => '</table>', |
1763 | 1773 |
'#weight' => $weight++, |
... | ... | |
1780 | 1790 |
} |
1781 | 1791 |
|
1782 | 1792 |
/** |
1783 |
* @todo Please document this function. |
|
1784 |
* @see http://drupal.org/node/1354 |
|
1793 |
* Callback for checkboxes preferred for widget which will |
|
1794 |
* be called after the form or element is built. The call |
|
1795 |
* back is configured in the form element by setting it as |
|
1796 |
* #after_build parameter. |
|
1797 |
* |
|
1798 |
* @see http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#after_build |
|
1799 |
* |
|
1800 |
* @param $form |
|
1801 |
* Nested array of form elements that comprise the form. |
|
1802 |
* @param $form_state |
|
1803 |
* A keyed array containing the current state of the form. |
|
1804 |
* |
|
1805 |
* @return the modified form array |
|
1785 | 1806 |
*/ |
1786 | 1807 |
function checkboxes_preferred_after_build($form, &$form_state) { |
1787 | 1808 |
|
Also available in: Unified diff
documenting checkboxes_preferred widget functions