function rules_scheduler_action_schedule_form_alter

Form alter callback for the schedule action.

Related topics

File

rules_scheduler/rules_scheduler.rules.inc, line 152

Code

function rules_scheduler_action_schedule_form_alter(&$form, &$form_state, $options, RulesAbstractPlugin $element) {
    $first_step = empty($element->settings['component']);
    $form['reload'] = array(
        '#weight' => 5,
        '#type' => 'submit',
        '#name' => 'reload',
        '#value' => $first_step ? t('Continue') : t('Reload form'),
        '#limit_validation_errors' => array(
            array(
                'parameter',
                'component',
            ),
        ),
        '#submit' => array(
            'rules_action_type_form_submit_rebuild',
        ),
        '#ajax' => rules_ui_form_default_ajax(),
    );
    // Use ajax and trigger as the reload button.
    $form['parameter']['component']['settings']['type']['#ajax'] = $form['reload']['#ajax'] + array(
        'event' => 'change',
        'trigger_as' => array(
            'name' => 'reload',
        ),
    );
    if ($first_step) {
        // In the first step show only the component select.
        foreach (element_children($form['parameter']) as $key) {
            if ($key != 'component') {
                unset($form['parameter'][$key]);
            }
        }
        unset($form['submit']);
        unset($form['provides']);
    }
    else {
        // Hide the reload button in case js is enabled and it's not the first step.
        $form['reload']['#attributes'] = array(
            'class' => array(
                'rules-hide-js',
            ),
        );
    }
}