You are here

item.inc in Finder 7.2

File

modules/finder_ui/includes/item.inc
View source
<?php

/**
 * @file
 * finder-item.inc
 *
 * Provides the Finder UI item related functions.
 */
finder_inc('common', 'finder_ui');

/**
 * Finder UI item page.
 *
 * @param $finder
 *  The finder object.
 * @param $item_key
 *  The item key.
 * @param $js
 *  The $js param required by ctools.
 * @return
 *  The output.
 */
function finder_ui_item_page($finder, $item_key, $js) {
  ctools_include('modal');
  ctools_include('ajax');
  ctools_include('object-cache');
  finder_inc('finder', 'finder_ui');
  $finder = ctools_object_cache_get('finder', $finder->name);
  $finder_ui = finder_ui($finder);
  $title = $finder_ui['items'][$item_key]['#item']['#title'];
  $item = $finder_ui['items'][$item_key];
  $form_state = array(
    'title' => $title,
    'ajax' => $js,
    'finder' => $finder,
    'item_key' => $item_key,
    'item' => $item,
  );
  $output = ctools_modal_form_wrapper('finder_ui_item_form', $form_state);
  if ($form_state['executed'] && $js) {
    if ($form_state['triggering_element']['#parents'][1] == 'submit') {
      $finder = ctools_object_cache_get('finder', $finder->name);
      foreach ($form_state['values'] as $key => $value) {
        if ($key != 'settings') {
          $finder->{$key} = $value;
        }
      }
      foreach ($form_state['values']['settings'] as $key => $value) {
        $finder->settings[$key] = $value;
      }
      ctools_object_cache_set('finder', $finder->name, $finder);
      $finder_ui = finder_ui($finder);
      $item = $finder_ui['items'][$item_key];
      $commands = array();
      $output = finder_ui_item($finder, $item_key, $item);
      $commands[] = ajax_command_html('#finder-ui-item-' . $item_key, $output);
      $commands[] = ajax_command_css('#edit-changed', array(
        'display' => 'block',
      ));
    }
    $commands[] = ctools_modal_command_dismiss();
    print ajax_render($commands);
    exit;
  }
  if ($js) {
    print ajax_render($output);
    exit;
  }

  // Otherwise, just return the output.
  return $output;
}

/**
 * Finder UI item form.
 *
 * @param $form
 *  The form array.
 * @param &$form_state
 *  The form state array.
 * @return
 *  The form array.
 */
function finder_ui_item_form($form, &$form_state) {
  ctools_include('dependent');
  $form['#tree'] = TRUE;
  $form = array_merge($form, $form_state['item']['#form']);
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Apply'),
  );
  $form['actions']['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
  );
  $form['#pre_render'] = array(
    'finder_ui_modal_form_pre_render',
  );
  return $form;
}

/**
 * Finder UI item form submit.
 *
 * @param $form
 *  The form array.
 * @param &$form_state
 *  The form state array.
 */
function finder_ui_item_form_submit($form, &$form_state) {
}

/**
 * Finder UI item.
 *
 * @param $form
 *  The form array.
 * @param &$form_state
 *  The form state array.
 * @return
 *  The output.
 */
function finder_ui_item($finder, $item_key, $item) {
  $output = $item['#item']['#title'] ? '<span class="label">' . $item['#item']['#title'] . ':</span>' : '';
  $value = strip_tags($item['#item']['#value']);

  // Ensure the value works out to something clickable.
  if (!$item['#item']['#value']) {

    // There is no original value.
    $value = '<em>' . t('empty') . '</em>';
  }
  elseif (!trim($value)) {

    // There is a value, but it is dodgy to display.
    $value = t('Yes');
  }
  $output .= finder_ui_modal_link($value, 'admin/structure/finder/list/' . $finder->name . '/item/' . $item_key . '/nojs', t('Edit'), 'ctools-modal-finder-modal-style');
  if (!empty($item['#item']['#extra'])) {
    $output .= '<span class="extra">' . $item['#item']['#extra'] . '</span>';
  }
  $getq = explode('/', $_GET['q']);
  if (end($getq) == 'ajax' && !empty($item['#item']['#refresh'])) {
    $output .= '<div class="finder-ui-needs-reload"></div>';
  }
  return $output;
}

Functions

Namesort descending Description
finder_ui_item Finder UI item.
finder_ui_item_form Finder UI item form.
finder_ui_item_form_submit Finder UI item form submit.
finder_ui_item_page Finder UI item page.