You are here

function properties_compare_list_form in Dynamic properties 7

Form builder function; display comparison list.

1 string reference to 'properties_compare_list_form'
properties_compare_block_view in properties_compare/properties_compare.module
Implements hook_block_view().

File

properties_compare/properties_compare.module, line 256
Module file for privatemsg_compare module.

Code

function properties_compare_list_form($form, &$form_state, $list) {
  drupal_add_css(drupal_get_path('module', 'properties_compare') . '/properties_compare.css');
  $items = array();
  $first = NULL;
  $noncomparable = FALSE;
  foreach ($list as $compare_item) {
    $entity = entity_load($compare_item['entity_type'], array(
      $compare_item['entity_id'],
    ));
    $entity = reset($entity);
    if (!$entity) {

      // Entity could not be loaded, ignore and remove from list.
      properties_compare_list_delete($compare_item['entity_type'], $compare_item['entity_id']);
      continue;
    }
    $uri = entity_uri($compare_item['entity_type'], $entity);
    $uri['options'] += array(
      'attributes' => array(
        'class' => array(
          'properties-compare-entity-link',
        ),
      ),
    );
    $suffix = '';
    $classes = array();
    if (!$first) {
      $first = $compare_item + array(
        'entity' => $entity,
      );
      $classes[] = 'properties-comparable';
    }
    else {
      $comparable = properties_compare_is_comparable($first['entity_type'], $first['entity'], $compare_item['entity_type'], $entity);
      if (!$comparable) {
        $suffix = ' *';
        $noncomparable = TRUE;
      }
      $classes[] = $comparable ? 'properties-comparable' : 'properties-not-comparable';
    }

    // View mode functionality only implemented for entity_type node.
    if ($compare_item['entity_type'] == 'node' && variable_get('properties_compare_view_mode', TRUE)) {
      $content = node_view($entity, 'properties_compare_block');
      $content['links']['#access'] = FALSE;
      $label = drupal_render($content);
      $uri['options']['html'] = TRUE;
    }
    else {
      $label = entity_label($compare_item['entity_type'], $entity);
    }
    $entity_link = l($label . $suffix, $uri['path'], $uri['options']);
    $delete_link = l(t('x', array(), array(
      'context' => 'delete',
    )), 'properties/compare/delete/' . $compare_item['entity_type'] . '/' . $compare_item['entity_id'], array(
      'query' => drupal_get_destination(),
    ));
    $items[] = array(
      'data' => t('!entity_link (!delete_link)', array(
        '!entity_link' => $entity_link,
        '!delete_link' => $delete_link,
      )),
      'class' => $classes,
    );
  }
  $form['items'] = array(
    '#theme' => 'item_list',
    '#items' => $items,
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['clear'] = array(
    '#type' => 'submit',
    '#submit' => array(
      'properties_compare_list_form_clear_submit',
    ),
    '#value' => t('Clear'),
  );
  if (count($items) > 1) {
    $form['actions']['compare'] = array(
      '#type' => 'submit',
      '#submit' => array(
        'properties_compare_list_form_compare_submit',
      ),
      '#value' => t('Compare'),
    );
  }
  if ($noncomparable) {
    $form['notice'] = array(
      '#markup' => '<div class="properties-not-comparable-notice" >' . t('* Can not be compared with current selection.') . '</div>',
    );
  }
  return $form;
}