You are here

public function MenuViews::load in Menu Views 7

File

includes/menu_views.class.inc, line 53
Provides methods for attaching a view to a menu item.

Class

MenuViews
Implements MenuViews() class.

Code

public function load($form = array(), $form_state = array()) {
  $this->name = FALSE;
  $this->display = FALSE;
  $this->arguments = '';
  $this->mlid = 0;
  $this->tree = FALSE;

  // Setup the appropriate paths for each $form and $form_state variance.
  if (isset($form['options'])) {
    $this->options = $form['options'];
  }

  // Set the tree variable to reflect the #tree condition of $form['options'], required in case other modules alter the form.
  if (isset($form['options']['#tree'])) {
    $this->tree = $form['options']['#tree'];
  }
  $form_original_values = FALSE;
  if (isset($form['original_item']['#value']['options'])) {
    $form_original_values = $form['original_item']['#value']['options'];
  }
  $form_state_values = FALSE;
  if (isset($form_state['values'])) {
    $form_state_values = $this->tree && isset($form_state['values']['options']) ? $form_state['values']['options'] : $form_state['values'];
  }

  // Recurse through $form and $form_state for possible values for the current state of the attached view.
  $properties = array(
    'name',
    'display',
    'arguments',
    'mlid',
  );
  foreach ($properties as $property) {

    // Check for submitted values in $form_state first.
    if ($form_state_values && isset($form_state_values['menu_views'][$property])) {
      $this->{$property} = $form_state_values['menu_views'][$property];
    }
    elseif ($form_original_values && isset($form_original_values['menu_views'][$property])) {
      $this->{$property} = $form_original_values['menu_views'][$property];
    }
    elseif ($this->options && isset($this->options['menu_views'][$property])) {
      $this->{$property} = $this->options['menu_views'][$property];
    }
  }
  $views = array_keys(views_get_enabled_views());
  if (!in_array($this->name, $views)) {
    $this->name = FALSE;
  }
  if ($this->name === FALSE) {
    $this->display = FALSE;
    $this->arguments = '';
  }
  else {
    if ($this->display === FALSE) {
      $this->arguments = '';
    }
  }
  return $this;
}