public function BlazyManagerBase::buildSkins in Blazy 7
Same name and namespace in other branches
- 8.2 src/BlazyManagerBase.php \Drupal\blazy\BlazyManagerBase::buildSkins()
- 8 src/BlazyManagerBase.php \Drupal\blazy\BlazyManagerBase::buildSkins()
Collects defined skins as registered via hook_MODULE_NAME_skins_info().
File
- src/
BlazyManagerBase.php, line 301
Class
- BlazyManagerBase
- Implements BlazyManagerInterface.
Namespace
Drupal\blazyCode
public function buildSkins($namespace, $skin_class, $methods = []) {
$cid = $namespace . ':skins';
if ($cache = cache_get($cid)) {
return $cache->data;
}
$classes = module_invoke_all($namespace . '_skins_info');
$classes = array_merge([
$skin_class,
], (array) $classes);
$items = $skins = [];
foreach ($classes as $class) {
if (class_exists($class)) {
$reflection = new \ReflectionClass($class);
if ($reflection
->implementsInterface($skin_class . 'Interface')) {
$skin = new $class();
if (empty($methods) && method_exists($skin, 'skins')) {
$items = $skin
->skins();
}
else {
foreach ($methods as $method) {
$items[$method] = method_exists($skin, $method) ? $skin
->{$method}() : [];
}
}
}
}
$skins = NestedArray::mergeDeep($skins, $items);
}
cache_set($cid, $skins, 'cache', CACHE_PERMANENT);
return $skins;
}