Skip to content

Commit d09e522

Browse files
authored
Merge pull request #2018 from khlystou/4.x
Added raw mode to password field
2 parents c1433c3 + 95b243d commit d09e522

6 files changed

Lines changed: 26 additions & 10 deletions

File tree

src/Laravel/src/Traits/Fields/WithAsyncSearch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function associatedWith(string $column, ?Closure $searchQuery = null): st
220220
$this->associatedWithSearchQuery = $searchQuery;
221221

222222
return $this->asyncSearch(
223-
searchQuery: \is_null($searchQuery) ? $defaultQuery : $searchQuery,
223+
searchQuery: $searchQuery ?? $defaultQuery,
224224
associatedWith: $column,
225225
);
226226
}

src/Support/src/Traits/WithComponentAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ private function xIfOrShow(
237237
if (! $variable instanceof Closure) {
238238
$o = \is_null($value) ? '=' : $operator;
239239
$o = $o === '=' ? '==' : $o;
240-
$v = \is_null($value) ? $operator : $value;
240+
$v = $value ?? $operator;
241241
$variable = static fn (self $ctx): string => "$variable$o'$v'";
242242
}
243243

src/UI/src/Collections/Fields.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function fillCloned(
159159
/** @var static */
160160
return ($preparedFields ?? $this->onlyFields(withApplyWrappers: true))->map(
161161
static fn (FieldContract $field): FieldContract => (clone $field)
162-
->fillData(\is_null($casted) ? $raw : $casted, $index)
162+
->fillData($casted ?? $raw, $index)
163163
);
164164
}
165165

@@ -177,7 +177,7 @@ public function fillClonedRecursively(
177177
);
178178
}
179179

180-
$component->fillData(\is_null($casted) ? $raw : $casted, $index);
180+
$component->fillData($casted ?? $raw, $index);
181181

182182
return clone $component;
183183
});
@@ -190,7 +190,7 @@ public function fill(array $raw = [], ?DataWrapperContract $casted = null, int $
190190
{
191191
$this->onlyFields(withApplyWrappers: true)->map(
192192
static fn (FieldContract $field): FieldContract => $field
193-
->fillData(\is_null($casted) ? $raw : $casted, $index)
193+
->fillData($casted ?? $raw, $index)
194194
);
195195
}
196196

src/UI/src/Components/FieldsGroup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function previewMode(): self
3030
public function fill(array $raw = [], ?DataWrapperContract $casted = null, int $index = 0): self
3131
{
3232
return $this->mapFields(
33-
static fn (FieldContract $field): FieldContract => $field->fillData(\is_null($casted) ? $raw : $casted, $index)
33+
static fn (FieldContract $field): FieldContract => $field->fillData($casted ?? $raw, $index)
3434
);
3535
}
3636

src/UI/src/Fields/Password.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class Password extends Text
1616

1717
protected ?TextWrap $textWrap = null;
1818

19+
protected bool $hashed = true;
20+
1921
protected function resolvePreview(): string
2022
{
2123
return '***';
@@ -26,11 +28,25 @@ protected function resolveValue(): string
2628
return '';
2729
}
2830

31+
protected function isHashed(): bool
32+
{
33+
return $this->hashed;
34+
}
35+
2936
public function isUnescape(): bool
3037
{
3138
return true;
3239
}
3340

41+
public function raw(Closure|bool|null $condition = null): static
42+
{
43+
$result = value($condition, $this) ?? true;
44+
45+
$this->hashed = ! $result;
46+
47+
return $this;
48+
}
49+
3450
protected function resolveOnApply(): ?Closure
3551
{
3652
return function ($item) {
@@ -40,7 +56,9 @@ protected function resolveOnApply(): ?Closure
4056
data_set(
4157
$item,
4258
$this->getColumn(),
43-
$this->getCore()->getContainer(Hasher::class)->make($value)
59+
$this->isHashed()
60+
? $this->getCore()->getContainer(Hasher::class)->make($value)
61+
: $value
4462
);
4563
}
4664

src/UI/src/Traits/Fields/Applies.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ public function apply(Closure $default, mixed $data): mixed
145145
);
146146
}
147147

148-
$applyFunction = \is_null($this->onApply)
149-
? $this->resolveOnApply()
150-
: $this->onApply;
148+
$applyFunction = $this->onApply ?? $this->resolveOnApply();
151149

152150
return \is_null($applyFunction)
153151
? $default($data, $this->getRequestValue(), $this)

0 commit comments

Comments
 (0)