Skip to content

Commit d7b550b

Browse files
authored
Fix action templates with url option (#259)
![image](https://github.com/user-attachments/assets/0dbdaace-37d2-4d5e-a511-5175ca63139b) - [x] Fix action templates with a defined url when the default route does not exist - [x] Add a disabled class when the path is empty ![image](https://github.com/user-attachments/assets/92ca2d6d-efb5-4a5b-8c3b-c7825062745b)
2 parents 08057ed + 9a8f57a commit d7b550b

File tree

7 files changed

+54
-6
lines changed

7 files changed

+54
-6
lines changed

app/Entity/Talk.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class Talk implements ResourceInterface
6666
#[NotBlank]
6767
private ?\DateTimeImmutable $endsAt = null;
6868

69+
#[ORM\Column(nullable: true)]
70+
private ?string $videoUrl = null;
71+
6972
#[ORM\Column(enumType: Track::class)]
7073
#[NotBlank]
7174
private ?Track $track = null;
@@ -129,6 +132,16 @@ public function setEndsAt(?\DateTimeImmutable $endsAt): void
129132
$this->endsAt = $endsAt;
130133
}
131134

135+
public function getVideoUrl(): ?string
136+
{
137+
return $this->videoUrl;
138+
}
139+
140+
public function setVideoUrl(?string $videoUrl): void
141+
{
142+
$this->videoUrl = $videoUrl;
143+
}
144+
132145
public function getTrack(): ?Track
133146
{
134147
return $this->track;

app/Factory/TalkFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public function withConference(Proxy|Conference $conference): self
7373
return $this->with(['conference' => $conference]);
7474
}
7575

76+
public function withVideoUrl(string $videoUrl): self
77+
{
78+
return $this->with(['videoUrl' => $videoUrl]);
79+
}
80+
7681
protected function defaults(): array|callable
7782
{
7883
return [

app/Grid/TalkGrid.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use App\Grid\Filter\SpeakerFilter;
2020
use Sylius\Bundle\GridBundle\Builder\Action\CreateAction;
2121
use Sylius\Bundle\GridBundle\Builder\Action\DeleteAction;
22+
use Sylius\Bundle\GridBundle\Builder\Action\ShowAction;
2223
use Sylius\Bundle\GridBundle\Builder\Action\UpdateAction;
2324
use Sylius\Bundle\GridBundle\Builder\ActionGroup\BulkActionGroup;
2425
use Sylius\Bundle\GridBundle\Builder\ActionGroup\ItemActionGroup;
@@ -94,6 +95,13 @@ public function buildGrid(GridBuilderInterface $gridBuilder): void
9495
)
9596
->addActionGroup(
9697
ItemActionGroup::create(
98+
ShowAction::create()
99+
->setOptions([
100+
'link' => [
101+
'url' => 'resource.videoUrl',
102+
],
103+
])
104+
->setIcon('tabler:video'),
97105
UpdateAction::create(),
98106
DeleteAction::create(),
99107
),

app/Story/DefaultSyliusCon2024TalksStory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ private function createTechTwoTalks(): void
278278
->withStartingDate(new \DateTimeImmutable('2024-11-13 11:00:00'))
279279
->withEndingDate(new \DateTimeImmutable('2024-11-13 11:45:00'))
280280
->withConference(ConferenceFactory::findOrCreate(['name' => 'SyliusCon 2024']))
281+
->withVideoUrl('https://www.youtube.com/watch?v=VgtygyxbdyM')
281282
->create()
282283
;
283284

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{% set id = options.link.parameters['id']|default(data.id) %}
22

3-
{% set path = options.link.url|default(path(options.link.route|default(grid.requestConfiguration.getRouteName('delete')), options.link.parameters|default({'id': id}))) %}
3+
{% if options.link.url is defined %}
4+
{% set path = options.link.url %}
5+
{% else %}
6+
{% set default_route = options.link.route|default(grid.requestConfiguration is defined ? grid.requestConfiguration.getRouteName('delete') : null) %}
7+
{% set path = options.link.url|default(default_route ? path(default_route, options.link.parameters|default({'id': data.id})): null) %}
8+
{% endif %}
49

5-
{{ component('sylius_bootstrap_admin_ui:delete_modal', {id: id, path: path, label: action.label, icon: action.icon}) }}
10+
{% set disabled = path is empty %}
11+
12+
{{ component('sylius_bootstrap_admin_ui:delete_modal', {id: id, path: path, label: action.label, icon: action.icon, disabled: disabled}) }}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
{% set path = options.link.url|default(path(options.link.route|default(grid.requestConfiguration.getRouteName('show')), options.link.parameters|default({'id': data.id}))) %}
1+
{% if options.link.url is defined %}
2+
{% set path = options.link.url %}
3+
{% else %}
4+
{% set default_route = options.link.route|default(grid.requestConfiguration is defined ? grid.requestConfiguration.getRouteName('show') : null) %}
5+
{% set path = options.link.url|default(default_route ? path(default_route, options.link.parameters|default({'id': data.id})): null) %}
6+
{% endif %}
7+
28
{% set message = action.label|default('sylius.ui.show') %}
9+
{% set disabled = path is empty %}
310

4-
<a title="details" href="{{ path }}" class="btn btn-icon" data-bs-toggle="tooltip" data-bs-title="{{ message|trans }}" {{ sylius_test_html_attribute('show-action', message|trans ) }}>
11+
<a title="details" href="{{ path }}" class="btn btn-icon {% if disabled %}disabled{% endif %}" data-bs-toggle="tooltip" data-bs-title="{{ message|trans }}" {{ sylius_test_html_attribute('show-action', message|trans ) }}>
512
{{ ux_icon(action.icon|default('tabler:eye')) }}
613
</a>
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
{% set path = options.link.url|default(path(options.link.route|default(grid.requestConfiguration.getRouteName('update')), options.link.parameters|default({'id': data.id}))) %}
1+
{% if options.link.url is defined %}
2+
{% set path = options.link.url %}
3+
{% else %}
4+
{% set default_route = options.link.route|default(grid.requestConfiguration is defined ? grid.requestConfiguration.getRouteName('update') : null) %}
5+
{% set path = options.link.url|default(default_route ? path(default_route, options.link.parameters|default({'id': data.id})): null) %}
6+
{% endif %}
7+
28
{% set message = action.label|default('sylius.ui.edit') %}
9+
{% set disabled = path is empty %}
310

4-
<a href="{{ path }}" class="btn btn-icon" data-bs-toggle="tooltip" data-bs-title="{{ message|trans }}">
11+
<a href="{{ path }}" class="btn btn-icon {% if disabled %}disabled{% endif %}" data-bs-toggle="tooltip" data-bs-title="{{ message|trans }}">
512
{{ ux_icon(action.icon|default('tabler:pencil')) }}
613
</a>

0 commit comments

Comments
 (0)