You are here

public static function ViewWidget::getRows in Entity Reference View Widget 8

Returns a renderable array of the rows.

Parameters

$entity_ids:

1 call to ViewWidget::getRows()
ModalForm::addItemsAjax in src/Form/ModalForm.php
Ajax callback for the the add items button.

File

src/Plugin/Field/FieldWidget/ViewWidget.php, line 216
Contains \Drupal\entity_reference_view_widget\Plugin\Field\FieldWidget\ViewWidget.

Class

ViewWidget
Plugin implementation of the 'entity_reference_view_widget' widget.

Namespace

Drupal\entity_reference_view_widget\Plugin\Field\FieldWidget

Code

public static function getRows($entity_ids, $settings) {
  $entity_ids = array_values($entity_ids);
  $rows = array();
  if (!empty($entity_ids)) {
    $entities = entity_load_multiple($settings['target_type'], $entity_ids);
    $max = count($entities);
    $delta = 0;
    foreach ($entities as $entity_id => $entity_item) {
      $rows[] = array(
        'target_id' => array(
          '#type' => 'checkbox',
          '#delta' => $delta,
          '#field_suffix' => String::checkPlain($entity_item
            ->label()),
          '#return_value' => $entity_id,
          '#value' => $entity_id,
        ),
        '_weight' => array(
          '#type' => 'weight',
          '#title' => t('Weight for row @number', array(
            '@number' => $delta + 1,
          )),
          '#title_display' => 'invisible',
          // Note: this 'delta' is the FAPI #type 'weight' element's property.
          '#delta' => $max,
          '#default_value' => $delta,
          '#weight' => 100,
        ),
      );
      $delta++;
    }
  }
  return $rows;
}