AddCssClasses.php in Facets Block 8
File
src/AddCssClasses.php
View source
<?php
namespace Drupal\facets_block;
use Drupal\Component\Utility\Html;
use Drupal\Core\Security\TrustedCallbackInterface;
class AddCssClasses implements TrustedCallbackInterface {
public static function trustedCallbacks() {
return [
'preRender',
];
}
public static function preRender($elements) {
if (empty($elements['#id'])) {
$elements['#id'] = Html::getUniqueId($elements['#plugin_id']);
}
if (empty($elements['content']['#facets'])) {
$elements['#attributes']['class'][] = 'hidden';
}
return $elements;
}
}