function widgets_element_form in Widgets 7
Form builder; Form for adding and editing widget elements.
This form is used universally for editing all widget elements. Each element adds its own custom section to the form by calling the form function specified in hook_widgets_elements().
Parameters
$form_state: An associative array containing the current state of the form.
$set: An widget set array.
$element: An widget element array.
See also
hook_widgets_elements()
widgets_resize_form()
widgets_scale_form()
widgets_rotate_form()
widgets_crop_form()
1 string reference to 'widgets_element_form'
- widgets_menu in ./
widgets.module - Implements hook_menu().
File
- ./
widgets.admin.inc, line 619 - Administration pages for widget settings.
Code
function widgets_element_form($form, &$form_state, $set, $element) {
if (!empty($element['data'])) {
$title = t('Edit %label element', array(
'%label' => $element['label'],
));
}
else {
$title = t('Add %label element', array(
'%label' => $element['label'],
));
$element['data'] = array();
}
drupal_set_title($title, PASS_THROUGH);
$form_state['widgets_set'] = $set;
$form_state['widgets_element'] = $element;
// If no configuration for this widget element, return to the widget set page.
if (!isset($element['form callback'])) {
drupal_goto('admin/structure/widgets/sets/edit/' . $set['name']);
}
$form['#tree'] = TRUE;
$form['#attached']['css'][drupal_get_path('module', 'widgets') . '/widgets.admin.css'] = array();
if (function_exists($element['form callback'])) {
$form['data'] = call_user_func($element['form callback'], $element['data']);
drupal_alter('widgets_element_form', $form['data'], $set, $element);
}
// Check the URL for a weight, then the widget element, otherwise use default.
$form['weight'] = array(
'#type' => 'hidden',
'#value' => isset($_GET['weight']) ? intval($_GET['weight']) : (isset($element['weight']) ? $element['weight'] : count($set['elements'])),
);
$form['actions'] = array(
'#tree' => FALSE,
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => isset($element['weid']) ? t('Update element') : t('Add element'),
);
$form['actions']['cancel'] = array(
'#type' => 'link',
'#title' => t('Cancel'),
'#href' => 'admin/structure/widgets/sets/edit/' . $set['name'],
);
return $form;
}