From 86c88ed1d927aa455b5ead6e84e5e65ffbdafe9f Mon Sep 17 00:00:00 2001 From: rendix2 Date: Fri, 24 Nov 2023 11:13:28 +0100 Subject: [PATCH] DataAttribute for InlineAdd and InlineEdit #1107 --- src/InlineEdit/InlineEdit.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/InlineEdit/InlineEdit.php b/src/InlineEdit/InlineEdit.php index 4dc31163..84c3c616 100644 --- a/src/InlineEdit/InlineEdit.php +++ b/src/InlineEdit/InlineEdit.php @@ -58,6 +58,9 @@ class InlineEdit */ protected bool $showNonEditingColumns = true; + /** @var array */ + protected array $dataAttributes = []; + public function __construct(protected Datagrid $grid, protected ?string $primaryWhereColumn = null) { $this->title = 'contributte_datagrid.edit'; @@ -94,6 +97,12 @@ public function renderButton(Row $row): Html $this->tryAddIcon($a, $this->getIcon(), $this->getText()); + if ($this->dataAttributes !== []) { + foreach ($this->dataAttributes as $key => $value) { + $a->data((string) $key, $value); + } + } + $a->addText($this->text); if ($this->title !== null) { @@ -122,6 +131,12 @@ public function renderButtonAdd(): Html $this->tryAddIcon($a, $this->getIcon(), $this->getText()); + if ($this->dataAttributes !== []) { + foreach ($this->dataAttributes as $key => $value) { + $a->data((string) $key, $value); + } + } + $a->addText($this->text); if ($this->title !== null) { @@ -199,4 +214,14 @@ public function showNonEditingColumns(): bool return $this->showNonEditingColumns; } + /** + * @return static + */ + public function setDataAttribute(string $key, mixed $value): self + { + $this->dataAttributes[$key] = $value; + + return $this; + } + }