File tree Expand file tree Collapse file tree
templates/EasyAdminBundle/Fields Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace App \Admin \Field ;
6+
7+ use EasyCorp \Bundle \EasyAdminBundle \Contracts \Field \FieldInterface ;
8+ use EasyCorp \Bundle \EasyAdminBundle \Field \FieldTrait ;
9+ use Symfony \Contracts \Translation \TranslatableInterface ;
10+
11+ class AffectedSitesField implements FieldInterface
12+ {
13+ use FieldTrait;
14+
15+ public static function new (string $ propertyName , TranslatableInterface |string |bool |null $ label = null ): self
16+ {
17+ return new self ()
18+ ->setProperty ($ propertyName )
19+ ->setLabel ($ label )
20+ ->setTemplatePath ('EasyAdminBundle/Fields/affected_sites.html.twig ' );
21+ }
22+ }
Original file line number Diff line number Diff line change 44
55namespace App \Controller \Admin ;
66
7+ use App \Admin \Field \AffectedSitesField ;
78use App \Admin \Field \SourcesField ;
89use App \Admin \Field \TextMonospaceField ;
910use App \Entity \Advisory ;
@@ -58,6 +59,7 @@ public function configureFields(string $pageName): iterable
5859 yield DateField::new ('reportedAt ' )->setColumns (6 )->onlyOnIndex ();
5960 yield DateTimeField::new ('reportedAt ' )->setColumns (6 )->onlyOnDetail ();
6061 yield SourcesField::new ('sourceLinks ' )->setColumns (6 )->onlyOnDetail ();
62+ yield AffectedSitesField::new ('sites ' )->setLabel ('Affected Sites ' );
6163 }
6264
6365 #[\Override]
Original file line number Diff line number Diff line change @@ -190,6 +190,25 @@ public function removePackageVersion(PackageVersion $packageVersion): self
190190 return $ this ;
191191 }
192192
193+ /**
194+ * @return Collection<int, Site>
195+ */
196+ public function getSites (): Collection
197+ {
198+ $ sites = new ArrayCollection ();
199+ foreach ($ this ->packageVersions as $ packageVersion ) {
200+ foreach ($ packageVersion ->getInstallations () as $ installation ) {
201+ foreach ($ installation ->getSites () as $ site ) {
202+ if (!$ sites ->contains ($ site )) {
203+ $ sites ->add ($ site );
204+ }
205+ }
206+ }
207+ }
208+
209+ return $ sites ;
210+ }
211+
193212 public function getPackage (): ?Package
194213 {
195214 return $ this ->package ;
Original file line number Diff line number Diff line change 1+ {# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
2+ {# @var field \EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto #}
3+ {# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
4+ {% set sites = entity .instance .sites %}
5+ {% if ea().crud.currentAction == ' detail' %}
6+ {% if sites | length > 0 %}
7+ <table class =" table table-sm table-borderless" >
8+ <thead >
9+ <tr >
10+ <th >Domain</th >
11+ <th >Server</th >
12+ </tr >
13+ </thead >
14+ <tbody >
15+ {% for site in sites %}
16+ {% set url = ea_url()
17+ .unsetAll()
18+ .setController(' App\\Controller\\Admin\\SiteCrudController' )
19+ .setAction(' detail' )
20+ .setEntityId(site .id ) %}
21+ <tr >
22+ <td ><a href =" {{ url }}" >{{ site .primaryDomain }}</a ></td >
23+ <td >{{ site .server }}</td >
24+ </tr >
25+ {% endfor %}
26+ </tbody >
27+ </table >
28+ {% else %}
29+ <span class =" text-muted" >None</span >
30+ {% endif %}
31+ {% else %}
32+ <span class =" badge badge-info" >{{ sites | length }}</span >
33+ {% endif %}
You can’t perform that action at this time.
0 commit comments