5 changed files with 95 additions and 51 deletions
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
<?php |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace App\Twig\Components\Organisms; |
||||
|
||||
use App\Entity\Event; |
||||
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; |
||||
use Symfony\UX\LiveComponent\DefaultActionTrait; |
||||
|
||||
#[AsLiveComponent] |
||||
final class MagazineHero |
||||
{ |
||||
use DefaultActionTrait; |
||||
|
||||
/** |
||||
* The magazine object/array (entity or hydrated structure) provided by the controller. |
||||
* @var mixed $magazine |
||||
*/ |
||||
public ?Event $magazine = null; |
||||
|
||||
/** |
||||
* Slug/identifier for the magazine (route parameter), optional fallback if magazine slug not present. |
||||
*/ |
||||
public ?string $mag = null; |
||||
|
||||
/** |
||||
* Compute category tags (those whose first element/key is the letter 'a'). |
||||
* Supports multiple magazine shapes (object with getTags(), public property, or array key). |
||||
* |
||||
* @return array<int, mixed> |
||||
*/ |
||||
public function getCategoryTags(): array |
||||
{ |
||||
$tags = []; |
||||
$magazine = $this->magazine; |
||||
|
||||
if ($magazine) { |
||||
$tags = $magazine->getTags(); |
||||
} |
||||
|
||||
if (!is_iterable($tags)) { |
||||
return []; |
||||
} |
||||
|
||||
// Filter: tag[0] === 'a' |
||||
$filtered = []; |
||||
foreach ($tags as $tag) { |
||||
if (is_array($tag) && isset($tag[0]) && $tag[0] === 'a') { |
||||
$filtered[] = $tag; |
||||
} |
||||
} |
||||
|
||||
return $filtered; |
||||
} |
||||
} |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
<div {{ attributes }}> |
||||
<section class="d-flex gap-3 center ln-section--newsstand mb-3"> |
||||
<div class="container mt-5 mb-5"> |
||||
<h1><a href="{{ path('magazine-index', {mag: mag}) }}">{{ magazine.title|default(magazine.slug|default(mag)) }}</a></h1> |
||||
{% if magazine.summary is defined and magazine.summary %} |
||||
<p class="eyebrow">{{ magazine.summary }}</p> |
||||
{% endif %} |
||||
|
||||
{# Use computed property via this.categoryTags #} |
||||
{% if this.categoryTags is not empty %} |
||||
<ul class="list-unstyled d-flex flex-row gap-3 justify-content-center mt-3"> |
||||
{% for catTag in this.categoryTags %} |
||||
<li class="list-inline-item"><twig:Molecules:CategoryLink :coordinate="catTag" :mag="mag" /></li> |
||||
{% endfor %} |
||||
</ul> |
||||
{% else %} |
||||
<p class="text-muted mt-4">No categories yet.</p> |
||||
{% endif %} |
||||
</div> |
||||
</section> |
||||
</div> |
||||
Loading…
Reference in new issue