You are here

function markup_view_process in Markup 6

Process the markup_widget element.

Build the form element. When creating a form using FAPI #process, note that $element['#value'] is already set.

The $fields array is in $form['#field_info'][$element['#field_name']].

1 string reference to 'markup_view_process'
markup_view_elements in contrib/markup_view/markup_view.module
Implements FAPI hook_elements().

File

contrib/markup_view/markup_view.module, line 174
Defines a field type for displaying a view on the node/edit form.

Code

function markup_view_process($element, $edit, $form_state, $form) {
  $field = $form['#field_info'][$element['#field_name']];

  // Retrieve selected view key.
  $view_key = $field['view'];

  // Return if no view selected.
  if (empty($view_key)) {
    return $element;
  }

  // Split view key into name and display_id.
  list($view_name, $display_id) = explode('|', $view_key);
  if (empty($view_name) || empty($display_id)) {
    return $element;
  }

  // Retrieve view object.
  $view = views_get_view($view_name);
  if ($view && $view
    ->access($display_id)) {
    $args = markup_view_get_arguments($element, $field, $form_state, $form);
    $view
      ->set_display($display_id);
    if (!empty($args) && is_array($args)) {
      $view
        ->set_arguments($args);
    }

    // We don't want to be able to navigate away from the form so set ajax to
    // be on.
    // This should be configurable and perhaps should carry a warning.
    $view->display_handler
      ->set_option('use_ajax', 1);
    $markup = $view
      ->preview();
    if ($field['widget']['use_view_title']) {
      $title = $view
        ->get_title();
    }
    else {
      $title = $element['#title'];
    }
    $element['element'] = array(
      '#type' => 'markup_element',
      '#title' => $title,
      '#markup' => $markup,
      '#value' => array(),
      '#display_style' => $field['widget']['display_style'],
    );
  }
  return $element;
}