Skip to content

Commit

Permalink
Pass slot instance down, instead of re-instantiating using template i…
Browse files Browse the repository at this point in the history
…n container.
  • Loading branch information
jesseleite committed Feb 6, 2025
1 parent 10d444c commit 82f98a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
17 changes: 15 additions & 2 deletions src/Forms/RenderableField.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,38 @@

class RenderableField implements Htmlable
{
protected $slot;
protected $isBlade = false;

public function __construct(protected $field, protected $data)
{
//
}

public function isBlade(bool $isBlade): void
public function slot(RenderableFieldSlot $slot): self
{
$this->slot = $slot;

collect($this->data['fields'] ?? [])
->each(fn ($field) => $field['field']->slot($slot));

return $this;
}

public function isBlade(bool $isBlade): self
{
$this->isBlade = $isBlade;

collect($this->data['fields'] ?? [])
->each(fn ($field) => $field['field']->isBlade($isBlade));

return $this;
}

public function toHtml(): string
{
$data = array_merge($this->data, [
'slot' => new RenderableFieldSlot(app('form-slot'), $this->isBlade),
'slot' => $this->slot,
]);

return $this->minifyFieldHtml(
Expand Down
10 changes: 5 additions & 5 deletions src/Forms/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ public function create()
*/
public function fields()
{
app()->instance('form-slot', $slot = $this->content);

$isBlade = $this->isAntlersBladeComponent();

$slot = new RenderableFieldSlot($this->content, $isBlade);

collect($this->context['fields'])
->each(fn ($field) => $field['field']->isBlade($isBlade));
->each(fn ($field) => $field['field']->slot($slot)->isBlade($isBlade));

if ($isBlade) {
return $this->tagRenderer->render('@foreach($fields as $field)'.$slot.'@endforeach', $this->context->all());
return $this->tagRenderer->render('@foreach($fields as $field)'.$this->content.'@endforeach', $this->context->all());
}

return Antlers::parse('{{ fields }}'.$slot.'{{ /fields }}', $this->context->all());
return Antlers::parse('{{ fields }}'.$this->content.'{{ /fields }}', $this->context->all());
}

/**
Expand Down

0 comments on commit 82f98a5

Please # to comment.