You are here

function views_content_views_row_edit in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 views_content/plugins/content_types/views_row.inc \views_content_views_row_edit()

File

views_content/plugins/content_types/views_row.inc, line 110

Code

function views_content_views_row_edit($form, &$form_state) {
  $conf = $form_state['conf'];
  $contexts = $form_state['contexts'];
  if (empty($contexts[$conf['context']])) {
    $form['markup'] = array(
      '#markup' => '<p>' . t('Invalid context selected.') . '</p>',
    );
    return $form;
  }
  if (!isset($contexts[$conf['context']]->argument)) {
    $name = $contexts[$conf['context']]->placeholder['conf']['name'];
    list($plugin, $view_data) = explode(':', $name);
    list($view_name, $display_id) = explode('-', $view_data);
  }
  else {
    $view_data = $contexts[$conf['context']]->argument;
    list($view_name, $display_id) = explode(':', $view_data);
  }
  $contexts[$conf['context']]->data['name'] = $view_name;
  $contexts[$conf['context']]->data['display'] = $display_id;
  $view = views_content_context_get_view($contexts[$conf['context']]);
  if (empty($view)) {
    $form['markup'] = array(
      '#markup' => '<p>' . t('Context contains an invalid view.') . '</p>',
    );
    return $form;
  }
  ctools_include('dependent');
  $form['limit_rows'] = array(
    '#type' => 'checkbox',
    '#title' => t('Limit rows'),
    '#default_value' => (int) (!empty($conf['rows'])),
  );
  $view
    ->init_pager();
  $rows = $view
    ->get_items_per_page();
  if (!empty($rows)) {
    foreach (range(1, $rows) as $row) {
      $options[$row] = t('Row @number', array(
        '@number' => $row,
      ));
    }
    $form['rows'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Select rows'),
      '#options' => $options,
      '#default_value' => $conf['rows'],
      '#dependency' => array(
        'edit-limit-rows' => array(
          TRUE,
        ),
      ),
    );
  }
  else {
    $form['rows'] = array(
      '#markup' => '<p>' . t('The view must have a maximum number of items set to use this setting.') . '</p>',
    );
    return $form;
  }
  if ($view->display_handler
    ->uses_fields()) {
    $form['use_fields'] = array(
      '#type' => 'checkbox',
      '#title' => t('Display specific fields'),
      '#default_value' => $conf['use_fields'],
    );
    $form['fields'] = array(
      '#type' => 'checkboxes',
      '#options' => $view->display_handler
        ->get_field_labels(),
      '#default_value' => $conf['fields'],
      '#prefix' => '<div id="edit-fields-wrapper"><div id="edit-fields">',
      '#suffix' => '</div></div>',
      '#dependency' => array(
        'edit-use-fields' => array(
          TRUE,
        ),
      ),
    );
  }
  return $form;
}