You are here

function relation_rules_load_related_form_alter in Relation 8.2

Same name and namespace in other branches
  1. 8 relation.rules.inc \relation_rules_load_related_form_alter()
  2. 7 relation.rules.inc \relation_rules_load_related_form_alter()

Form alter callback for the load_related action.

File

./relation.rules.inc, line 225
Implements the Rules module API for Relation.

Code

function relation_rules_load_related_form_alter(&$form, &$form_state, $options, RulesAbstractPlugin $element) {
  $first_step = empty($element->settings['relation_type']);
  $form['reload'] = array(
    '#weight' => 5,
    '#type' => 'submit',
    '#name' => 'reload',
    '#value' => $first_step ? t('Continue') : t('Reload form'),
    '#submit' => array(
      'rules_action_type_form_submit_rebuild',
    ),
    '#ajax' => rules_ui_form_default_ajax(),
    '#description' => $first_step ? '' : t('Reload the form to change the entity types list.'),
  );
  if ($first_step) {

    // In the first step only show relevant parameters.
    foreach (Element::children($form['parameter']) as $key) {
      if ($key != 'relation_type' && $key != 'left') {
        unset($form['parameter'][$key]);
      }
    }
    unset($form['submit']);
    unset($form['provides']);
  }

  // Add #ajax to the relation_type selection dropdown to reload the form.
  if (isset($form['parameter']['relation_type'])) {
    $form['parameter']['relation_type']['#ajax'] = rules_ui_form_default_ajax() + array(
      'event' => 'change',
      'trigger_as' => array(
        'name' => 'reload',
      ),
    );
  }
}