You are here

protected function RulesPluginUI::getParameterForm in Rules 7.2

Actually generates the parameter form for the given data type.

1 call to RulesPluginUI::getParameterForm()
RulesPluginUI::form in ui/ui.core.inc
Implements RulesPluginUIInterface::form().

File

ui/ui.core.inc, line 298
Contains core Rules UI functions.

Class

RulesPluginUI
Faces UI extender for all kind of Rules plugins.

Code

protected function getParameterForm($name, $info, $settings, &$mode) {
  $class = $this
    ->getDataTypeClass($info['type'], $info);
  $supports_input_mode = in_array('RulesDataDirectInputFormInterface', class_implements($class));

  // Init the mode.
  if (!isset($mode)) {
    if (isset($settings[$name . ':select'])) {
      $mode = 'selector';
    }
    elseif (isset($settings[$name]) && $supports_input_mode) {
      $mode = 'input';
    }
    elseif (isset($info['restriction'])) {
      $mode = $info['restriction'];
    }
    else {

      // Allow the parameter to define the 'default mode' and fallback to the
      // data type default.
      $mode = !empty($info['default mode']) ? $info['default mode'] : call_user_func(array(
        $class,
        'getDefaultMode',
      ));
    }
  }

  // For translatable parameters, pre-populate an internal translation source
  // key so data type forms or input evaluators (i18n) may show a suitable
  // help message.
  if (drupal_multilingual() && !empty($info['translatable'])) {
    $parameter = $this->element
      ->pluginParameterInfo();
    $info['custom translation language'] = !empty($parameter['language']);
  }

  // Add the parameter form.
  if ($mode == 'input' && $supports_input_mode) {
    $form['settings'] = call_user_func(array(
      $class,
      'inputForm',
    ), $name, $info, $settings, $this->element);
  }
  else {
    $form['settings'] = call_user_func(array(
      $class,
      'selectionForm',
    ), $name, $info, $settings, $this->element);
  }

  // Add a link for switching the input mode when JS is enabled and a button
  // to switch it without JavaScript, in case switching is possible.
  if ($supports_input_mode && empty($info['restriction'])) {
    $value = $mode == 'selector' ? t('Switch to the direct input mode') : t('Switch to data selection');
    $form['switch_button'] = array(
      '#type' => 'submit',
      '#name' => 'param_' . $name,
      '#attributes' => array(
        'class' => array(
          'rules-switch-button',
        ),
      ),
      '#parameter' => $name,
      '#value' => $value,
      '#submit' => array(
        'rules_ui_parameter_replace_submit',
      ),
      '#ajax' => rules_ui_form_default_ajax('none'),
      // Do not validate!
      '#limit_validation_errors' => array(),
    );
  }
  return $form;
}