new react block
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Drupal\ufc\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Entity\EntityTypeManager;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\Core\Cache\CacheableJsonResponse;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
@@ -34,7 +35,7 @@ class RecentFightsController extends ControllerBase {
|
||||
$query = $this->entityTypeManager->getStorage('node')->getQuery();
|
||||
$query->accessCheck(TRUE);
|
||||
$query->condition('type', 'fight')->sort('created', 'DESC');
|
||||
$query->range(0, 12);
|
||||
$query->range(0, 13);
|
||||
$nids = $query->execute();
|
||||
$all_fights = Node::loadMultiple($nids);
|
||||
$fights = [];
|
||||
@@ -44,14 +45,24 @@ class RecentFightsController extends ControllerBase {
|
||||
$result = Node::load($fight->field_result->target_id);
|
||||
$alias = \Drupal::service('path_alias.manager')->getAliasByPath("/" . $fight->toUrl()->getInternalPath());
|
||||
if ($f1 && $f2) {
|
||||
|
||||
$f1_uri = $f1->field_player_photo->entity->field_media_image->entity->getFileUri() ?? 'public://player-headshots/headshot-default.jpeg';
|
||||
$f2_uri = $f2->field_player_photo->entity->field_media_image->entity->getFileUri() ?? 'public://player-headshots/headshot-default.jpeg';
|
||||
|
||||
$f1_pic_url = str_replace("public://", "/sites/default/files/", $f1_uri);
|
||||
$f2_pic_url = str_replace("public://", "sites/default/files/", $f2_uri);
|
||||
|
||||
$fights[] = [
|
||||
'fighter_one' => $f1->getTitle(),
|
||||
'fighter_one_image' => $f1_pic_url,
|
||||
'fighter_two' => $f2->getTitle(),
|
||||
'fighter_two_image' => $f2_pic_url,
|
||||
'result' => $result->getTitle(),
|
||||
'url' => $alias
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return new CacheableJsonResponse($fights);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user