57 lines
1.6 KiB
PHP
Raw Normal View History

2024-03-13 15:48:45 +00:00
<?php
use Drupal\views\ViewExecutable;
2024-04-09 01:47:04 +00:00
use Drupal\node\NodeInterface;
2024-03-13 15:48:45 +00:00
/**
* Implements hook_theme().
*
* Register a module or theme's theme implementations.
* The implementations declared by this hook specify how a particular render array is to be rendered as HTML.
*
* See: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_theme/8.2.x
*
* If you change this method, clear theme registry and routing table 'drush cc theme-registry' and 'drush cc router'.
*/
function ufc_theme($existing, $type, $theme, $path) {
return [
2024-04-09 01:47:04 +00:00
'fighters_dcjs' => [
2024-03-13 15:48:45 +00:00
'variables' => [
2024-04-09 01:47:04 +00:00
'count' => 0,
],
],
'fighters_dcjs_list' => [
'variables' => [
'fighters' => [],
],
],
'fighter_for_dcjs' => [
'variables' => [
'node' => NULL,
'personal_info' => [],
'stats' => [],
2024-03-13 15:48:45 +00:00
],
],
];
}
2024-04-09 01:47:04 +00:00
function ufc_views_pre_view(ViewExecutable $view) {
if ($view->id() !== 'fighter_fight_list' || $view->getDisplay()->display['id'] !== 'past_fights') {
2024-03-13 15:48:45 +00:00
return;
}
2024-04-09 01:47:04 +00:00
$node = \Drupal::routeMatch()->getParameter('node');
assert($node instanceof NodeInterface);
$fighter_name = \Drupal::routeMatch()->getParameter('node')->getTitle();
$filters = $view->display_handler->getOption('filters');
$filters['combine']['value'] = $fighter_name;
$view->display_handler->overrideOption('filters', $filters);
2024-03-13 15:48:45 +00:00
}
2024-04-09 01:47:04 +00:00
function ufc_preprocess_block(&$vars) {
if ($vars['plugin_id'] !== 'views_block:fighter_fight_list-past_fights') {
return;
2024-03-13 15:48:45 +00:00
}
2024-04-09 01:47:04 +00:00
$vars['#cache']['contexts'] = ['url.path', 'url.query_args', 'user.permissions'];
2024-03-13 15:48:45 +00:00
}