You are here

public static function EntityCheck::getEntityList in Entity Update 8

Same name and namespace in other branches
  1. 2.0.x src/EntityCheck.php \Drupal\entity_update\EntityCheck::getEntityList()

Get entity list.

Parameters

string $type: The entity type id.

int $start: Start from.

int $length: The max length.

bool $print: Print to the drush terminal.

Return value

array The table (Renderer array).

2 calls to EntityCheck::getEntityList()
drush_entity_update_entity_check in ./entity_update.drush.inc
Call back function of entity-check.
EntityList::buildForm in src/Form/EntityList.php
Form constructor.

File

src/EntityCheck.php, line 66

Class

EntityCheck
EntityCheck Main Class.

Namespace

Drupal\entity_update

Code

public static function getEntityList($type, $start = 0, $length = 10, $print = TRUE) {

  // Cast to integer.
  $start = (int) $start;
  $length = (int) $length;
  $entities = [];
  try {

    // Get entities list.
    $query = \Drupal::entityQuery($type);
    if ($length) {
      $query
        ->range($start, $length);
    }
    $ids = $query
      ->execute();
    $entities = \Drupal::entityTypeManager()
      ->getStorage($type)
      ->loadMultiple($ids);
  } catch (\Exception $ex) {
    EntityUpdatePrint::drushLog($ex
      ->getMessage(), 'error');
    return NULL;
  }

  // Create table.
  $table = [
    '#theme' => 'table',
    '#caption' => 'List of the entities : ' . $type,
    '#header' => [
      'ID',
      'Label',
    ],
    '#rows' => [],
  ];
  foreach ($entities as $id => $entiy) {
    $table['#rows'][] = [
      $id,
      $entiy
        ->label(),
    ];
  }

  // Print table.
  if ($print) {
    EntityUpdatePrint::drushPrintTable($table);
  }
  return $table;
}