Back to Access class

Method cleanAssetKey

protected static int|string
cleanAssetKey
(mixed $assetKey = null)
Method to clean the asset key to make sure we always have something.
Parameters
  • int|string $assetKey The asset key (asset id or asset name). null fallback to root asset.
Returns
  • int|string Asset id or asset name.
Since
  • 3.7.0
Class: Access
Project: Joomla

Method cleanAssetKey - Source code

/**
 * Method to clean the asset key to make sure we always have something.
 *
 * @param   integer|string  $assetKey  The asset key (asset id or asset name). null fallback to root asset.
 *
 * @return  integer|string  Asset id or asset name.
 *
 * @since   3.7.0
 */
protected static function cleanAssetKey($assetKey = null)
{
    // If it's a valid asset key, clean it and return it.
    if ($assetKey) {
        return strtolower(preg_replace('#[\\s\\-]+#', '.', trim($assetKey)));
    }
    // Return root asset id if already preloaded.
    if (self::$rootAssetId !== null) {
        return self::$rootAssetId;
    }
    // No preload. Return root asset id from Assets.
    $assets = new Asset(Factory::getDbo());
    return $assets->getRootId();
}