You are here

class AddCssClasses in Facets Block 8

AddCssClasses pre-render callback.

Hierarchy

Expanded class hierarchy of AddCssClasses

File

src/AddCssClasses.php, line 11

Namespace

Drupal\facets_block
View source
class AddCssClasses implements TrustedCallbackInterface {

  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    return [
      'preRender',
    ];
  }

  /**
   * Pre-render callback to add hidden class to empty facet block.
   */
  public static function preRender($elements) {
    if (empty($elements['#id'])) {
      $elements['#id'] = Html::getUniqueId($elements['#plugin_id']);
    }

    // Hide facets block if facets array is empty.
    if (empty($elements['content']['#facets'])) {
      $elements['#attributes']['class'][] = 'hidden';
    }
    return $elements;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AddCssClasses::preRender public static function Pre-render callback to add hidden class to empty facet block.
AddCssClasses::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.