You are here

function flag_plugin_argument_validate_flaggability::validate_form in Flag 6

Same name and namespace in other branches
  1. 6.2 includes/flag_plugin_argument_validate_flaggability.inc \flag_plugin_argument_validate_flaggability::validate_form()

File

includes/flag_plugin_argument_validate_flaggability.inc, line 20
Contains the flaggability validator handler.

Class

flag_plugin_argument_validate_flaggability
Validates whether an argument is a flaggable/flagged object.

Code

function validate_form(&$form, &$form_state) {
  $options = $this
    ->flags_options();
  $form[$this
    ->_option_name('flag_name')] = array(
    '#type' => 'radios',
    // Add an ID to the surrounding div because radios don't get IDs
    // as a whole group. This is needed for #dependency.
    '#prefix' => '<div><div id="edit-options-' . views_css_safe($this
      ->_option_name('flag_name')) . '">',
    '#suffix' => '</div></div>',
    '#title' => t('Flag'),
    '#options' => $options,
    '#default_value' => $this
      ->_get_option('flag_name', '*relationship*'),
    '#description' => t('Select the flag to validate against.'),
    '#process' => array(
      'expand_radios',
      'views_process_dependency',
    ),
    '#dependency' => array(
      'edit-options-validate-type' => array(
        $this->id,
      ),
    ),
  );
  if (!$options) {
    $form[$this
      ->_option_name('flag_name')]['#description'] = '<p class="warning">' . t('No %type flags exist. You must first <a href="@create-url">create a %type flag</a> before being able to use one.', array(
      '%type' => $this->flag_type,
      '@create-url' => 'admin/build/flags',
    )) . '</p>';
  }
  $form[$this
    ->_option_name('flag_test')] = array(
    '#type' => 'select',
    '#title' => t('Validate the @type only if', array(
      '@type' => $this->flag_type,
    )),
    '#options' => $this
      ->tests_options(),
    '#default_value' => $this
      ->_get_option('flag_test', 'flaggable'),
    '#process' => array(
      'views_process_dependency',
    ),
    '#dependency' => array(
      'edit-options-validate-type' => array(
        $this->id,
      ),
    ),
  );

  // This validator supports the "multiple IDs" syntax. It may not be
  // extremely useful, but similar validators do support this and it's a good
  // thing to be compatible.
  $form[$this
    ->_option_name('flag_id_type')] = array(
    '#type' => 'select',
    '#title' => t('Argument type'),
    '#options' => array(
      'id' => t('ID'),
      'ids' => t('IDs separated by , or +'),
    ),
    '#default_value' => $this
      ->_get_option('flag_id_type', 'id'),
    '#process' => array(
      'views_process_dependency',
    ),
    '#dependency' => array(
      'edit-options-validate-type' => array(
        $this->id,
      ),
    ),
  );
}