Commit 62763f24 authored by surgemartin's avatar surgemartin Committed by Martin Anderson-Clutz
Browse files

Issue #3254750 by mandclu: WSOD for some entity types

parent c55b8ae3
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -140,11 +140,20 @@ class GridController extends ControllerBase {
   *   Render array to be displayed.
   */
  public function getTable($entity_type_id, $bundle) {
    $bundle_key = $this->entityTypeManager->getDefinition($entity_type_id)->getKey('bundle');
    if (empty($bundle_key) || !$this->entityTypeManager->hasHandler($entity_type_id, 'list_builder')) {
      \Drupal::messenger()->addWarning('Unsupported Entity Type.');
      return $this->redirect('autogrid.choose_entity_type');
    }

    // @todo make the pager length configurable.
    $pager = 10;

    // Build the header first so we can sort on columns.
    $fields = $this->entityFieldManager->getFieldDefinitions($entity_type_id, $bundle);

    // @todo make display of base fields configurable.
    $include = ['body', 'title', 'name'];
    // Include the id, which can have different names.
    $include[] = array_key_first($fields);
    foreach ($fields as $field_name => $field_definition) {
@@ -158,7 +167,7 @@ class GridController extends ControllerBase {

    $query = \Drupal::entityQuery($entity_type_id)
      ->tableSort($header)
      ->condition('type', $bundle)
      ->condition($bundle_key, $bundle)
      ->pager($pager);
    $results = $query->execute();
    if (!$results) {
@@ -170,9 +179,6 @@ class GridController extends ControllerBase {
    $storage = $this->entityTypeManager->getStorage($entity_type_id);
    $entities = $storage->loadMultiple($results);
    $this->entityListBuilder = $this->entityTypeManager->getListBuilder($entity_type_id);

    // @todo make display of base fields configurable.
    $include = ['body', 'title', 'name'];
    $rows = [];
    foreach ($entities as $entity) {
      $rows[] = $this->buildRow($entity);
@@ -211,7 +217,7 @@ class GridController extends ControllerBase {
    $entity_definitions = $this->entityTypeManager->getDefinitions();
    $entities = [];
    foreach ($entity_definitions as $definition_id => $definition) {
      if ($definition instanceof ConfigEntityType) {
      if ($definition instanceof ConfigEntityType || !$this->entityTypeManager->getDefinition($definition_id)->getKey('bundle') || !$this->entityTypeManager->hasHandler($definition_id, 'list_builder')) {
        continue;
      }
      $url = Url::fromRoute('autogrid.choose_bundle', ['entity_type_id' => $definition_id]);
@@ -238,9 +244,13 @@ class GridController extends ControllerBase {
   *   The list of links to choose from.
   */
  public function getBundleLinks($entity_type_id) {
    $bundle_key = $this->entityTypeManager->getDefinition($entity_type_id)->getKey('bundle');
    if (empty($bundle_key) || !$this->entityTypeManager->hasHandler($entity_type_id, 'list_builder')) {
      \Drupal::messenger()->addWarning('Unsupported Entity Type.');
      return $this->redirect('autogrid.choose_entity_type');
    }
    $bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo($entity_type_id);
    $links = [];
    // @todo if one one bundle, redirect automatically.
    foreach ($bundles as $bundle_name => $bundle_info) {
      $url = Url::fromRoute('autogrid.display', ['entity_type_id' => $entity_type_id, 'bundle' => $bundle_name]);
      // @todo add access check?