/**
* Deactivate list of assets provided by Preset item.
*
* @param string $name The asset name
*
* @return self
*
* @throws UnsatisfiedDependencyException When Asset dependency cannot be found
*
* @since 4.0.0
*/
protected function disablePresetItems($name) : WebAssetManagerInterface
{
// Get the asset object
$asset = $this->registry->get('preset', $name);
// Call disableAsset() to each of its dependency
foreach ($asset->getDependencies() as $dependency) {
$depType = '';
$depName = $dependency;
$pos = strrpos($dependency, '#');
// Check for cross-dependency "dependency-name#type" case
if ($pos) {
$depType = substr($dependency, $pos + 1);
$depName = substr($dependency, 0, $pos);
}
$depType = $depType ?: 'preset';
// Make sure dependency exists
if (!$this->registry->exists($depType, $depName)) {
throw new UnsatisfiedDependencyException(sprintf('Unsatisfied dependency "%s" for an asset "%s" of type "%s"', $dependency, $name, 'preset'));
}
$this->disableAsset($depType, $depName);
}
return $this;
}