You are here

public function WsBean::form in Web Service Data 7

Builds extra settings for the block edit form.

Overrides BeanPlugin::form

File

modules/wsbeans/plugins/beans/wsbeans_wsbean.inc, line 32
Listing bean plugin.

Class

WsBean
@file Listing bean plugin.

Code

public function form($bean, $form, &$form_state) {
  $form = array();
  $form['settings'] = array(
    '#type' => 'fieldset',
    '#tree' => 1,
    '#title' => t('WsBean Settings'),
    '#description' => t('To render content into a wsbean, the data is retrived by the selected Web Service Configure, then if is parsed by the Web Service Processor, the result of that is then passed to the given theme hook to be rendered.'),
  );
  $form['settings']['wsconfig_settings'] = array(
    '#type' => 'fieldset',
    '#tree' => 1,
    '#title' => t('WsConfig Settings'),
  );
  $form['settings']['wsconfig_settings']['wsconfig'] = array(
    '#type' => 'select',
    '#title' => t('Web Service Config'),
    '#description' => t('The web service config to use to retrieve the data'),
    '#options' => wsconfig_get_list_by_name(),
    '#default_value' => isset($bean->settings['wsconfig_settings']['wsconfig']) ? $bean->settings['wsconfig_settings']['wsconfig'] : '',
  );
  foreach (wsconfig_get_list_by_name() as $machinename => $name) {
    $wsconfig = wsconfig_load_by_name($machinename);
    $items = array();
    foreach ($wsconfig
      ->getOperations() as $opname) {
      $items[$opname] = $wsconfig
        ->getMethodName($opname);
    }
    $form['settings']['wsconfig_settings']['wsconfig_method_' . $machinename] = array(
      '#type' => 'select',
      '#title' => t('Web Service Config Method'),
      '#description' => t('The web service method to use'),
      '#options' => $items,
      '#default_value' => isset($bean->settings['wsconfig_settings']['wsconfig_method_' . $machinename]) ? $bean->settings['wsconfig_settings']['wsconfig_method_' . $machinename] : '',
      '#states' => array(
        'visible' => array(
          ':input[name="settings[wsconfig_settings][wsconfig]"]' => array(
            'value' => $machinename,
          ),
        ),
      ),
    );
    if (module_exists('bean_panels_context')) {
      ctools_include('context');
      $converters = ctools_context_get_all_converters();
    }
    foreach ($wsconfig
      ->getOperations() as $opname) {
      foreach ($wsconfig
        ->getReplacements($opname) as $arg) {
        if (module_exists('bean_panels_context')) {
          $form['settings']['wsconfig_settings']['replacements']['wsconfig_method_' . $machinename][$arg] = array(
            '#type' => 'select',
            '#title' => t('@arg from context', array(
              '@arg' => $arg,
            )),
            '#description' => t('Which type of context to use for this argument.'),
            '#default_value' => isset($bean->settings['wsconfig_settings']['replacements']['wsconfig_method_' . $machinename][$arg]) ? $bean->settings['wsconfig_settings']['replacements']['wsconfig_method_' . $machinename][$arg] : NULL,
            '#options' => $converters,
            '#states' => array(
              'visible' => array(
                ':input[name="settings[wsconfig_settings][wsconfig]"]' => array(
                  'value' => $machinename,
                ),
                ':input[name="settings[wsconfig_settings][wsconfig_method_' . $machinename . ']"]' => array(
                  'value' => $opname,
                ),
              ),
            ),
          );
        }
        $form['settings']['wsconfig_settings']['replacements']['wsconfig_method_' . $machinename][$arg . '_default'] = array(
          '#type' => 'textfield',
          '#title' => t('Default value for @arg', array(
            '@arg' => $arg,
          )),
          '#description' => t('Default value to use when context is not available.'),
          '#default_value' => isset($bean->settings['wsconfig_settings']['replacements']['wsconfig_method_' . $machinename][$arg . '_default']) ? $bean->settings['wsconfig_settings']['replacements']['wsconfig_method_' . $machinename][$arg . '_default'] : '',
          '#states' => array(
            'visible' => array(
              ':input[name="settings[wsconfig_settings][wsconfig]"]' => array(
                'value' => $machinename,
              ),
              ':input[name="settings[wsconfig_settings][wsconfig_method_' . $machinename . ']"]' => array(
                'value' => $opname,
              ),
            ),
          ),
        );
      }
    }
  }
  $form['settings']['wsconfig_settings']['arguments'] = array(
    '#type' => 'textfield',
    '#title' => t('Arguments'),
    '#description' => t('JSON encoded arguments to pass to the wsconfig'),
    '#default_value' => isset($bean->settings['arguments']) ? $bean->settings['arguments'] : '',
  );
  $form['settings']['wsconfig_settings']['options'] = array(
    '#type' => 'textfield',
    '#title' => t('Options'),
    '#description' => t('JSON encoded options'),
    '#default_value' => isset($bean->settings['options']) ? $bean->settings['options'] : '',
  );
  $form['settings']['wsprocessor'] = array(
    '#type' => 'select',
    '#title' => t('Web Service Processor'),
    '#description' => t('The web service processor to parse the data'),
    '#options' => wsconfig_get_form_processors(),
    '#default_value' => isset($bean->settings['wsprocessor']) ? $bean->settings['wsprocessor'] : '',
  );
  $form['settings']['themehook'] = array(
    '#type' => 'textfield',
    '#title' => t('Theme Hook'),
    '#description' => t('The name of the theme hook to render the data received from the processor with.'),
    '#default_value' => isset($bean->settings['themehook']) ? $bean->settings['themehook'] : '',
  );
  return $form;
}