You are here

function theme_relation_entity_collector_table in Relation 8

Same name and namespace in other branches
  1. 8.2 relation_entity_collector/relation_entity_collector.module \theme_relation_entity_collector_table()
  2. 7 relation_entity_collector/relation_entity_collector.module \theme_relation_entity_collector_table()

Creates a draggable table out of the entities already picked.

File

relation_entity_collector/relation_entity_collector.module, line 133
Relation Entity Collector Block.

Code

function theme_relation_entity_collector_table($variables) {
  $form = $variables['form'];
  $table['header'] = array();
  $table['attributes']['id'] = 'relation-entity-collector-table';
  $table['rows'] = array();
  drupal_add_tabledrag($table['attributes']['id'], 'order', 'sibling', 'relation-entity-collector-weight');
  foreach (Element::children($form['weight']) as $key) {
    $form['weight'][$key]['#attributes']['class'] = array(
      'relation-entity-collector-weight',
    );
    $data = array(
      $form['remove'][$key]['#entity_key']['entity_label'],
    );
    foreach ($form['#entity_collector_columns'] as $column) {
      $data[] = \Drupal::service('renderer')
        ->render($form[$column][$key]);
    }
    $table['rows'][] = array(
      'data' => $data,
      'class' => array(
        'draggable',
      ),
    );
  }
  $output = '';
  if ($table['rows']) {
    $output .= theme('table', $table);
  }
  foreach ($form as $form_element) {
    $output .= \Drupal::service('renderer')
      ->render($form_element);
  }
  return $output;
}