Skip to content
Snippets Groups Projects

convert and move remaining core hook implementations

Open nicxvan requested to merge issue/drupal-3494908:3494908-pp-1-mark-several into 11.x
3 unresolved threads
Files
48
<?php
namespace Drupal\big_pipe\Hook;
use Drupal\Core\Hook\Attribute\Hook;
/**
* Theme suggestions for big_pipe.
*/
class BigPipeThemeSuggestionsHooks {
/**
* Implements hook_theme_suggestions_HOOK().
*/
#[Hook('theme_suggestions_big_pipe_interface_preview')]
public function themeSuggestionsBigPipeInterfacePreview(array $variables) : array {
$common_callbacks_simplified_suggestions = [
'Drupal_block_BlockViewBuilder__lazyBuilder' => 'block',
];
$suggestions = [];
$suggestion = 'big_pipe_interface_preview';
if ($variables['callback']) {
$callback = preg_replace('/[^a-zA-Z0-9]/', '_', $variables['callback']);
if (is_array($callback)) {
$callback = implode('__', $callback);
}
// Use simplified template suggestion, if any.
// For example, this simplifies
// big-pipe-interface-preview--Drupal-block-BlockViewBuilder--lazyBuilder--<BLOCK ID>.html.twig
// to
// big-pipe-interface-preview--block--<BLOCK ID>.html.twig
if (isset($common_callbacks_simplified_suggestions[$callback])) {
$callback = $common_callbacks_simplified_suggestions[$callback];
}
$suggestions[] = $suggestion .= '__' . $callback;
if (is_array($variables['arguments'])) {
$arguments = preg_replace('/[^a-zA-Z0-9]/', '_', $variables['arguments']);
foreach ($arguments as $argument) {
if (empty($argument)) {
continue;
}
$suggestions[] = $suggestion . '__' . $argument;
}
}
}
return $suggestions;
}
}
Loading