new things

This commit is contained in:
Dan Chadwick
2024-04-14 21:54:51 -07:00
parent 4eb7bf6220
commit 6ad2ed7b29
5 changed files with 39 additions and 16 deletions

View File

@@ -34,15 +34,16 @@ class RecentFightsController extends ControllerBase {
public function getRecentFights() {
$query = $this->entityTypeManager->getStorage('node')->getQuery();
$query->accessCheck(TRUE);
$query->condition('type', 'fight')->sort('created', 'DESC')->sort('nid', 'DESC');
$query->range(0, 13);
$query->condition('type', 'fight')->sort('field_fight_date', 'DESC');
$query->range(0, 15);
$nids = $query->execute();
$all_fights = Node::loadMultiple($nids);
$fights = [];
foreach ($all_fights as $fight) {
$f1 = Node::load($fight->field_fighter_one->target_id);
$f2 = Node::load($fight->field_fighter_two->target_id);
$result = Node::load($fight->field_result->target_id);
/* $result = Node::load($fight->field_result->target_id) ?? FALSE; */
$alias = \Drupal::service('path_alias.manager')->getAliasByPath("/" . $fight->toUrl()->getInternalPath());
if ($f1 && $f2) {
@@ -57,7 +58,6 @@ class RecentFightsController extends ControllerBase {
'fighter_one_image' => $f1_pic_url,
'fighter_two' => $f2->getTitle(),
'fighter_two_image' => $f2_pic_url,
'result' => $result->getTitle(),
'url' => $alias
];
}