You are here

function matrix_handler_field_field::render_item in Matrix field 8.2

Same name in this branch
  1. 8.2 views/views_handler_field_field_matrix.inc \matrix_handler_field_field::render_item()
  2. 8.2 src/matrix_handler_field_field.php \Drupal\matrix\matrix_handler_field_field::render_item()

Render all or part of the matrix according to the settings.

Matrix bundles the entire table into the first item/delta slot so this function only get's called once and is passed a render array.

Assuming you use the default formatter of course! Alternative formatters aren't going to work here. So beware!

File

src/matrix_handler_field_field.php, line 120

Class

matrix_handler_field_field
A field that displays fields.

Namespace

Drupal\matrix

Code

function render_item($count, $item) {
  $element = $item['rendered'];
  if ($this->options['row']) {
    foreach ($element['#rows'] as $x => $row) {
      if ($x != $this->options['row']) {
        unset($element['#rows'][$x]);
      }
    }
  }
  if ($this->options['col']) {
    foreach ($element['#rows'] as $x => $row) {
      foreach ($row as $y => $col) {
        if ($y && $y != $this->options['col']) {
          unset($element['#rows'][$x][$y]);
        }
      }
    }
    foreach ($element['#header'] as $y => $header) {
      if ($y && $y != $this->options['col']) {
        unset($element['#header'][$y]);
      }
    }
  }
  if (!$this->options['show_col_headers']) {
    foreach ($element['#rows'] as $x => $row) {
      unset($element['#rows'][$x][0]);
    }
  }
  if (!$this->options['show_row_headers']) {
    $element['#header'] = array();
  }
  return $element;
}