You are here

public function EntityHelper::getEntityInstanceIds in Simple XML sitemap 4.x

Gets the entity IDs by entity type and bundle.

Parameters

string $entity_type_id: The entity type ID.

string|null $bundle_name: The bundle name.

Return value

array An array of entity IDs

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

src/Entity/EntityHelper.php, line 194

Class

EntityHelper
Helper class for working with entities.

Namespace

Drupal\simple_sitemap\Entity

Code

public function getEntityInstanceIds(string $entity_type_id, ?string $bundle_name = NULL) : array {
  $sitemap_entity_types = $this
    ->getSupportedEntityTypes();
  if (!isset($sitemap_entity_types[$entity_type_id])) {
    return [];
  }
  $entity_query = $this->entityTypeManager
    ->getStorage($entity_type_id)
    ->getQuery();
  if ($bundle_name !== NULL && !$this
    ->entityTypeIsAtomic($entity_type_id)) {
    $keys = $sitemap_entity_types[$entity_type_id]
      ->getKeys();

    // Menu fix.
    $keys['bundle'] = $entity_type_id === 'menu_link_content' ? 'menu_name' : $keys['bundle'];
    $entity_query
      ->condition($keys['bundle'], $bundle_name);
  }
  return $entity_query
    ->execute();
}