You are here

function finder_ui_element_list in Finder 7.2

Finder UI element list.

Parameters

$finder: The finder object.

Return value

The form array.

3 calls to finder_ui_element_list()
finder_ui_element_delete_page in modules/finder_ui/includes/element.inc
Finder UI element delete page.
finder_ui_element_page in modules/finder_ui/includes/element.inc
Finder UI element page.
finder_ui_page in modules/finder_ui/includes/finder.inc
Finder UI page.

File

modules/finder_ui/includes/element.inc, line 1002

Code

function finder_ui_element_list($finder) {
  finder_inc('element-item', 'finder_ui');
  finder_inc('field', 'finder_ui');
  if (!empty($finder->elements)) {
    $form['elements'] = array(
      '#prefix' => '<div class="description finder-ui-elements-table-desc">' . t('Elements can be organised here in a tree.  Drag elements to the right when they are under container elements to group them within that container.  Drag elements up and down to change their order.') . '</div>',
      '#theme' => 'finder_ui_elements_table',
    );
    foreach ($finder->elements as $key => $element) {

      // Reset messed up parent property.
      if (empty($finder->elements[$element->parent])) {
        $finder->elements[$key]->parent = NULL;
      }
      $columns = array();
      $form['elements'][$element->id]['leaf']['#type'] = 'value';
      $form['elements'][$element->id]['leaf']['#value'] = $element->element_handler['type'] == 'form';
      $form['elements'][$element->id]['value']['#prefix'] = '<div id="finder-ui-element-' . $element->id . '" class="finder-element">';
      $form['elements'][$element->id]['value']['#suffix'] = '</div>';
      $form['elements'][$element->id]['value']['info']['#prefix'] = '<div class="finder-ui-element-info">';
      $form['elements'][$element->id]['value']['info']['#suffix'] = '</div>';
      $menu = array(
        'links' => array(
          'edit' => array(
            'title' => t('Edit element info'),
            'href' => 'admin/structure/finder/list/' . $finder->name . '/element/' . $element->id . '/nojs',
            'html' => TRUE,
            'attributes' => array(
              'class' => array(
                'ctools-use-modal',
                'ctools-modal-finder-modal-style',
              ),
            ),
          ),
          'delete' => array(
            'title' => t('Delete element'),
            'href' => 'admin/structure/finder/list/' . $finder->name . '/delete-element/' . $element->id . '/nojs',
            'html' => TRUE,
            'attributes' => array(
              'class' => array(
                'ctools-use-modal',
                'ctools-modal-finder-modal-style',
              ),
            ),
          ),
        ),
      );
      $form['elements'][$element->id]['value']['info']['extra']['#markup'] = theme('links__ctools_dropbutton', $menu);
      $form['elements'][$element->id]['value']['info']['title']['#prefix'] = '<div class="finder-element-title">';
      $form['elements'][$element->id]['value']['info']['title']['#markup'] = '<strong>' . check_plain($element->title) . '</strong> ';
      $form['elements'][$element->id]['value']['info']['title']['#suffix'] = '</div>';
      $form['elements'][$element->id]['value']['info']['type']['#prefix'] = '<div class="finder-element-type">';
      $form['elements'][$element->id]['value']['info']['type']['#markup'] = '<span>' . $finder
        ->element_handler($element, 'title') . '</span> ';
      $form['elements'][$element->id]['value']['info']['type']['#suffix'] = '</div>';
      $form['elements'][$element->id]['value']['settings'] = array(
        '#type' => 'fieldset',
        '#title' => t('Settings'),
        '#collapsible' => TRUE,
        '#collapsed' => !($element->element_handler['type'] == 'form' && !$finder
          ->esetting($element, 'fields')),
        '#attached' => array(
          'js' => array(
            'misc/form.js',
            'misc/collapse.js',
          ),
        ),
        '#attributes' => array(
          'class' => array(
            'collapsible',
            'collapsed',
          ),
        ),
      );
      $columns['#prefix'] = '<div class="finder-ui-columns">';
      $columns['#suffix'] = '</div>';
      $finder_ui = finder_ui_element($finder, $element->id);
      $finder_items = array();
      $stripe = 'odd';
      foreach ($finder_ui['items'] as $item_key => $item) {
        $stripe = $stripe == 'odd' ? 'even' : 'odd';
        $finder_items[$item['#group']][$item_key]['#prefix'] = '<div class="finder-ui-item ' . $stripe . '" id="finder-ui-element-' . $element->id . '-item-' . $item_key . '">';
        $finder_items[$item['#group']][$item_key]['#markup'] = finder_ui_element_item($finder, $element->id, $item_key, $item);
        $finder_items[$item['#group']][$item_key]['#suffix'] = '</div>';
      }

      // Fields group is a special case.
      $finder_items['fields']['fields'] = finder_ui_field_list($finder, $element->id);
      $finder_items['fields']['fields']['#prefix'] = '<div id="finder-ui-element-' . $element->id . '-fields-list" class="finder-ui-item finder-ui-field-list">';
      $finder_items['fields']['fields']['#suffix'] = '</div>';
      foreach (array_keys($finder_ui['groups']) as $column) {
        $columns[$column]['#prefix'] = '<div class="finder-ui-column" id="finder-ui-column-' . $column . '">';
        $columns[$column]['#suffix'] = '</div>';
        foreach ($finder_ui['groups'][$column] as $group_key => $group) {
          $extra = '';
          if ($group_key == 'fields') {

            // Fields group is a special case.
            $menu = array(
              'links' => array(
                'edit' => array(
                  'title' => t('Add'),
                  'href' => 'admin/structure/finder/list/' . $finder->name . '/field/' . $element->id . '/new/nojs',
                  'html' => TRUE,
                  'attributes' => array(
                    'class' => array(
                      'ctools-use-modal',
                      'ctools-modal-finder-modal-style',
                    ),
                  ),
                ),
              ),
            );
            $extra = theme('links__ctools_dropbutton', $menu);
          }
          $columns[$column][$group_key]['#prefix'] = '<div class="finder-ui-group" id="finder-ui-group-' . $group_key . '">';
          $columns[$column][$group_key]['#suffix'] = '</div>';
          $columns[$column][$group_key]['title']['#prefix'] = '<div class="finder-ui-group-title" id="finder-ui-group-' . $group_key . '-title">';
          $columns[$column][$group_key]['title']['#markup'] = $extra . '<h3>' . $group . '</h3>';
          $columns[$column][$group_key]['title']['#suffix'] = '</div>';
          $columns[$column][$group_key]['items'] = $finder_items[$group_key];
        }
      }
      $form['elements'][$element->id]['value']['settings']['columns'] = $columns;
      $form['elements'][$element->id]['depth'] = array(
        '#type' => 'value',
        '#value' => $finder
          ->element_depth($element),
      );
      $form['elements'][$element->id]['weight'] = array(
        '#title' => t('Weight'),
        '#type' => 'weight',
        '#delta' => count($finder->elements) + 1,
        '#default_value' => isset($element->weight) ? $element->weight : count($finder->elements) + 1,
      );
      $form['elements'][$element->id]['source'] = array(
        '#type' => 'hidden',
        '#value' => $element->id,
      );
      $form['elements'][$element->id]['parent'] = array(
        '#type' => 'hidden',
        '#default_value' => isset($element->parent) ? $element->parent : NULL,
      );
    }
  }
  else {
    $form['no_elements'] = array(
      '#prefix' => '<div class="messages error">',
      '#markup' => t('There are currently no elements configured for this finder.'),
      '#suffix' => '</div>',
    );
  }
  return $form;
}