Skip to content

Commit

Permalink
Refactor renderContainerTag method to accept an optional id parameter. (
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Dec 30, 2023
1 parent de1c219 commit 3bd2b30
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/Attribute/Custom/HasContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ public function getContainerId(): string|null
return $id;
}

private function renderContainerTag(string ...$content): string
private function renderContainerTag(string|null $id, string ...$content): string
{
return match ($this->container) {
true => Tag::widget()
->attributes($this->containerAttributes)
->content(...$content)
->id($id)
->tagName($this->containerTag)
->render(),
default => implode(PHP_EOL, $content),
Expand Down
1 change: 1 addition & 0 deletions src/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ protected function run(): string
}

return $this->renderContainerTag(
null,
Tag::widget()
->attributes($attributes)
->content($this->content)
Expand Down
37 changes: 19 additions & 18 deletions src/Input/Base/AbstractButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,24 @@ protected function run(): string
$attributes['aria-describedby'] = "$id-help";
}

$inputTag = Tag::widget()
->attributes($attributes)
->id($id)
->prefix($this->prefix)
->prefixContainer($this->prefixContainer)
->prefixContainerAttributes($this->prefixContainerAttributes)
->prefixContainerTag($this->prefixContainerTag)
->suffix($this->suffix)
->suffixContainer($this->suffixContainer)
->suffixContainerAttributes($this->suffixContainerAttributes)
->suffixContainerTag($this->suffixContainerTag)
->tagName('input')
->template($this->template)
->tokenValue('{label}', $this->renderLabelTag($labelFor))
->type($type)
->render();

return $this->renderContainerTag($inputTag);
return $this->renderContainerTag(
null,
Tag::widget()
->attributes($attributes)
->id($id)
->prefix($this->prefix)
->prefixContainer($this->prefixContainer)
->prefixContainerAttributes($this->prefixContainerAttributes)
->prefixContainerTag($this->prefixContainerTag)
->suffix($this->suffix)
->suffixContainer($this->suffixContainer)
->suffixContainerAttributes($this->suffixContainerAttributes)
->suffixContainerTag($this->suffixContainerTag)
->tagName('input')
->template($this->template)
->tokenValue('{label}', $this->renderLabelTag($labelFor))
->type($type)
->render()
);
}
}
2 changes: 1 addition & 1 deletion src/Input/Base/AbstractButtonGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function individualContainer(bool $value): static

protected function run(): string
{
return $this->renderContainerTag($this->renderButtons());
return $this->renderContainerTag(null, $this->renderButtons());
}

private function renderButtons(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Input/Base/AbstractInputChoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function buildChoiceTag(string $type): string

$choiceTag = $this->prepareTemplate($tag, $labelTag);

return $this->renderContainerTag($choiceTag);
return $this->renderContainerTag(null, $choiceTag);
}

private function prepareTemplate(string $tag, string $labelTag): string
Expand Down

0 comments on commit 3bd2b30

Please sign in to comment.