You are here

public static function Asset::loadByAlias in Mini site 8

Load asset by alias.

Parameters

string $alias: Alias of the asset to load by.

Return value

\Drupal\minisite\Asset|null Class instance or NULL if asset cannot be loaded.

Overrides AssetInterface::loadByAlias

3 calls to Asset::loadByAlias()
AliasSubscriber::onRequestSetController in src/EventSubscriber/AliasSubscriber.php
Set Minisite delivery controller if request URI matches asset alias.
AssetTest::testAssetInstance in tests/src/Functional/AssetTest.php
Test working with Asset class instance.
AssetTest::testSaveLong in tests/src/Functional/AssetTest.php
Test Asset::save().

File

src/Asset.php, line 220

Class

Asset
Class Asset.

Namespace

Drupal\minisite

Code

public static function loadByAlias($alias) {
  if (!UrlHelper::isValid($alias)) {
    return NULL;
  }
  $values = Database::getConnection()
    ->select('minisite_asset', 'ma')
    ->fields('ma')
    ->condition('alias', $alias)
    ->orderBy('id', 'DESC')
    ->execute()
    ->fetchAssoc();
  if (empty($values)) {
    return NULL;
  }
  return self::fromValues($values);
}