Skip to content

Commit ebfa2e8

Browse files
authored
Moving getContents Back
1 parent 28360e2 commit ebfa2e8

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

src/Views/Columns/ArrayColumn.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use Rappasoft\LaravelLivewireTables\Views\Columns\Traits\Configuration\ArrayColumnConfiguration;
77
use Rappasoft\LaravelLivewireTables\Views\Columns\Traits\Helpers\ArrayColumnHelpers;
88
use Rappasoft\LaravelLivewireTables\Views\Columns\Traits\IsColumn;
9+
use Illuminate\Database\Eloquent\Model;
10+
use Illuminate\Support\HtmlString;
11+
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
912

1013
class ArrayColumn extends Column
1114
{
@@ -32,4 +35,31 @@ public function __construct(string $title, ?string $from = null)
3235
$this->label(fn () => null);
3336
}
3437
}
38+
39+
40+
public function getContents(Model $row): null|string|\BackedEnum|HtmlString|DataTableConfigurationException|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
41+
{
42+
$outputValues = [];
43+
$value = $this->getValue($row);
44+
45+
if (! $this->hasDataCallback()) {
46+
throw new DataTableConfigurationException('You must set a data() method on an ArrayColumn');
47+
}
48+
49+
if (! $this->hasOutputFormatCallback()) {
50+
throw new DataTableConfigurationException('You must set an outputFormat() method on an ArrayColumn');
51+
}
52+
53+
foreach (call_user_func($this->getDataCallback(), $value, $row) as $i => $v) {
54+
$outputValues[] = call_user_func($this->getOutputFormatCallback(), $i, $v);
55+
}
56+
57+
$returnedValue = (! empty($outputValues) ? implode($this->getSeparator(), $outputValues) : $this->getEmptyValue());
58+
59+
if ($this->hasOutputWrapperStart() && $this->hasOutputWrapperEnd()) {
60+
$returnedValue = $this->getOutputWrapperStart().$returnedValue.$this->getOutputWrapperEnd();
61+
}
62+
63+
return new HtmlString($returnedValue);
64+
}
3565
}

src/Views/Columns/Traits/Helpers/ArrayColumnHelpers.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Views\Columns\Traits\Helpers;
44

5-
use Illuminate\Database\Eloquent\Model;
6-
use Illuminate\Support\HtmlString;
7-
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
85

96
trait ArrayColumnHelpers
107
{
@@ -63,29 +60,4 @@ public function getOutputWrapperEnd(): string
6360
return $this->outputWrapperEnd;
6461
}
6562

66-
public function getContents(Model $row): null|string|\BackedEnum|HtmlString|DataTableConfigurationException|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
67-
{
68-
$outputValues = [];
69-
$value = $this->getValue($row);
70-
71-
if (! $this->hasDataCallback()) {
72-
throw new DataTableConfigurationException('You must set a data() method on an ArrayColumn');
73-
}
74-
75-
if (! $this->hasOutputFormatCallback()) {
76-
throw new DataTableConfigurationException('You must set an outputFormat() method on an ArrayColumn');
77-
}
78-
79-
foreach (call_user_func($this->getDataCallback(), $value, $row) as $i => $v) {
80-
$outputValues[] = call_user_func($this->getOutputFormatCallback(), $i, $v);
81-
}
82-
83-
$returnedValue = (! empty($outputValues) ? implode($this->getSeparator(), $outputValues) : $this->getEmptyValue());
84-
85-
if ($this->hasOutputWrapperStart() && $this->hasOutputWrapperEnd()) {
86-
$returnedValue = $this->getOutputWrapperStart().$returnedValue.$this->getOutputWrapperEnd();
87-
}
88-
89-
return new HtmlString($returnedValue);
90-
}
9163
}

0 commit comments

Comments
 (0)