Unverified Commit dd096348 authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch Committed by Mateu Aguiló Bosch
Browse files

Issue #3306889 by e0ipso: Use the new audit hook to state block support

parent 747c9125
Loading
Loading
Loading
Loading

cl_block.module

0 → 100644
+34 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Module implementation file.
 */

use Drupal\cl_components\Component\Component;
use Drupal\cl_components\Component\ComponentDiscovery;

/**
 * Implements hook_cl_component_audit_alter().
 */
function cl_block_cl_component_audit_alter(array &$card_build, Component $component): void {
  $card_build['table']['#header'][] = \t('Block Support');
  $allowed_components = &drupal_static(__FUNCTION__);
  if (!isset($allowed_components)) {
    $settings = \Drupal::config('cl_block.settings');
    $discovery = \Drupal::service(ComponentDiscovery::class);
    assert($discovery instanceof ComponentDiscovery);
    $allowed_components = array_map(
      static fn(Component $c) => $c->getId(),
      $discovery->findAllWithFilters(
        $settings->get('allowed'),
        $settings->get('forbidden'),
        $settings->get('types'),
        $settings->get('statuses'),
      )
    );
  }
  $card_build['table']['#rows'][0][] = in_array($component->getId(), $allowed_components)
    ? \t('✅ Generates a block')
    : \t('⛔ No block');
}