You are here

function asset_injector_get_assets in Asset Injector 8.2

Same name and namespace in other branches
  1. 8 asset_injector.module \asset_injector_get_assets()

Get all available assets.

Parameters

bool|null $active: Get only active (true), inactive (false), or all (null) assets.

array $types: Array of entity type ids to limit the return.

Return value

\Drupal\asset_injector\AssetInjectorInterface[] Assets from css & js injectors.

6 calls to asset_injector_get_assets()
AssetInjectorCssTest::testCssInjector in tests/src/Functional/AssetInjectorCssTest.php
Test a created css injector is added to the page and the css file exists.
AssetInjectorJsTest::testJsInjector in tests/src/Functional/AssetInjectorJsTest.php
Test a created css injector is added to the page and the css file exists.
asset_injector_ckeditor_css_alter in ./asset_injector.module
Implements hook_ckeditor_css_alter().
asset_injector_library_info_build in ./asset_injector.module
Implements hook_library_info_build().
asset_injector_page_attachments in ./asset_injector.module
Implements hook_page_attachments().

... See full list

File

./asset_injector.module, line 137
Contains module asset_injector.

Code

function asset_injector_get_assets($active = NULL, array $types = []) {

  /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
  $entity_type_manager = \Drupal::entityTypeManager();
  $assets = [];
  foreach (asset_injector_get_entity_types($types) as $entity_type_id => $entity_type) {
    $entity_type_storage = $entity_type_manager
      ->getStorage($entity_type_id);
    $asset_ids = $entity_type_storage
      ->getQuery()
      ->execute();
    foreach ($entity_type_storage
      ->loadMultiple($asset_ids) as $asset) {

      // Get both active and not active assets.
      if (is_null($active)) {
        $assets[] = $asset;
      }
      else {
        $access = $asset
          ->access('view');

        // Get only active assets.
        if ($active && $access) {
          $assets[] = $asset;
        }
        elseif (!$active && !$access) {
          $assets[] = $asset;
        }
      }
    }
  }
  return $assets;
}