From bc4e664cdd9a5c4e8eee1b756e83721b80b426e4 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 11 Apr 2025 12:49:36 +0300 Subject: [PATCH 1/4] Add `prepend`/`append` options to `BaseListView` --- src/BaseListView.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/BaseListView.php b/src/BaseListView.php index 66998954d..649c7d9aa 100644 --- a/src/BaseListView.php +++ b/src/BaseListView.php @@ -115,6 +115,8 @@ abstract class BaseListView extends Widget */ private ?string $containerTag = 'div'; private array $containerAttributes = []; + private string $prepend = ''; + private string $append = ''; /** * @psalm-var non-empty-string|null @@ -248,6 +250,30 @@ final public function containerAttributes(array $attributes): static return $new; } + /** + * Returns a new instance with HTML content to be added after the open container tag. + * + * @param string $prepend The HTML content to be prepended. + */ + final public function prepend(string $prepend): static + { + $new = clone $this; + $new->prepend = $prepend; + return $new; + } + + /** + * Returns a new instance with HTML content to be added before the close container tag. + * + * @param string $append The HTML content to be appended. + */ + final public function append(string $append): static + { + $new = clone $this; + $new->append = $append; + return $new; + } + /** * Return a new instance with the empty text. * @@ -543,6 +569,13 @@ final public function render(): string ) ); + if ($this->prepend !== '') { + $content = $this->prepend . "\n" . $content; + } + if ($this->append !== '') { + $content .= "\n" . $this->append; + } + return $this->containerTag === null ? $content : Html::tag($this->containerTag, "\n" . $content . "\n", $this->containerAttributes) From 5a26cc6e5fec51da7dbc4d19c2bd364381574fa0 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Fri, 11 Apr 2025 12:53:19 +0300 Subject: [PATCH 2/4] improve --- src/BaseListView.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BaseListView.php b/src/BaseListView.php index 649c7d9aa..4ebea0a08 100644 --- a/src/BaseListView.php +++ b/src/BaseListView.php @@ -253,24 +253,24 @@ final public function containerAttributes(array $attributes): static /** * Returns a new instance with HTML content to be added after the open container tag. * - * @param string $prepend The HTML content to be prepended. + * @param string|Stringable $prepend The HTML content to be prepended. */ - final public function prepend(string $prepend): static + final public function prepend(string|Stringable $prepend): static { $new = clone $this; - $new->prepend = $prepend; + $new->prepend = (string) $prepend; return $new; } /** * Returns a new instance with HTML content to be added before the close container tag. * - * @param string $append The HTML content to be appended. + * @param string|Stringable $append The HTML content to be appended. */ - final public function append(string $append): static + final public function append(string|Stringable $append): static { $new = clone $this; - $new->append = $append; + $new->append = (string) $append; return $new; } From 997a5bc0f8ae19755c7a24e74e604e732e78633f Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 15 Apr 2025 09:56:44 +0300 Subject: [PATCH 3/4] Update src/BaseListView.php Co-authored-by: Alexander Makarov --- src/BaseListView.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BaseListView.php b/src/BaseListView.php index 4ebea0a08..fb4ef41f2 100644 --- a/src/BaseListView.php +++ b/src/BaseListView.php @@ -251,7 +251,7 @@ final public function containerAttributes(array $attributes): static } /** - * Returns a new instance with HTML content to be added after the open container tag. + * Returns a new instance with HTML content to be added after the opening container tag. * * @param string|Stringable $prepend The HTML content to be prepended. */ From 67a75fba1e9cc5661ad97eabb147d718cd64949f Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 15 Apr 2025 09:56:50 +0300 Subject: [PATCH 4/4] Update src/BaseListView.php Co-authored-by: Alexander Makarov --- src/BaseListView.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BaseListView.php b/src/BaseListView.php index fb4ef41f2..7d5a9ed8d 100644 --- a/src/BaseListView.php +++ b/src/BaseListView.php @@ -263,7 +263,7 @@ final public function prepend(string|Stringable $prepend): static } /** - * Returns a new instance with HTML content to be added before the close container tag. + * Returns a new instance with HTML content to be added before the closing container tag. * * @param string|Stringable $append The HTML content to be appended. */