You are here

public function state_flow_handler_filter_state::get_value_options in State Machine 7.3

Same name and namespace in other branches
  1. 7 modules/state_flow/includes/views/state_flow_handler_filter_state.inc \state_flow_handler_filter_state::get_value_options()
  2. 7.2 modules/state_flow/includes/views/state_flow_handler_filter_state.inc \state_flow_handler_filter_state::get_value_options()

Provide value options for the state filter.

Returns the value options for the state filter based on available workflow states for any content types that could be included in this view.

Overrides views_handler_filter_in_operator::get_value_options

File

modules/state_flow/includes/views/state_flow_handler_filter_state.inc, line 16
Views filter handler for the State Flow state.

Class

state_flow_handler_filter_state
@file Views filter handler for the State Flow state.

Code

public function get_value_options() {
  if (isset($this->value_options)) {
    return;
  }
  if ($this->view->base_table == 'node') {

    // Determine the content types that could be part of this view. If the
    // node type filter is enabled, then limit to the selected types.
    $node_types = array();
    if (isset($this->view->filter) && is_array($this->view->filter)) {
      foreach ($this->view->filter as $key => $value) {
        if (get_class($value) === 'views_handler_filter_node_type') {
          $type_names = FALSE;
          if (!empty($this->view->exposed_input[$key]) && !empty($this->view->filter[$key]->value_options) && array_key_exists($this->view->exposed_input[$key], $this->view->filter[$key]->value_options)) {
            $type_names = array(
              $this->view->exposed_input[$key],
            );
          }
          elseif (!empty($this->view->filter[$key]->options['value'])) {
            $type_names = $this->view->filter[$key]->options['value'];
          }
          if (is_array($type_names)) {
            $node_types += $type_names;
          }
        }
      }
    }
    if (empty($node_types)) {
      $node_types = node_type_get_types();
    }
    ctools_include('plugins');

    // For all possible content types, load the appropriate state machine and
    // determine possible states.
    foreach ($node_types as $type => $value) {
      $node = new stdClass();
      $node->type = $type;
      $node->uid = isset($GLOBALS['user']->uid) ? $GLOBALS['user']->uid : 0;
      $node->title = '';
      $machine = state_flow_entity_load_state_machine($node, 'node');
      if ($machine instanceof StateFlowEntity) {
        $options = $machine
          ->get_states_options();
        foreach ($options as $name => $option) {
          $this->value_options[$name] = $option['label'];
        }
      }
    }
  }
  else {
    $states = workbench_workflows_options('states');
    $this->value_options = array();
    foreach ($states as $name => $state) {
      $this->value_options[$name] = $state;
    }
  }
}