-
-
Notifications
You must be signed in to change notification settings - Fork 24
Add DataField visibility setting #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -300,7 +300,7 @@ | |||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* @psalm-return list< | ||||||||||
Check failure on line 303 in src/DetailView.php
|
||||||||||
* array{ | ||||||||||
* label: string, | ||||||||||
* labelAttributes: array<array-key, mixed>, | ||||||||||
|
@@ -338,10 +338,11 @@ | |||||||||
, | ||||||||||
'valueAttributes' => $this->renderAttributes($valueAttributes), | ||||||||||
'valueTag' => $valueTag, | ||||||||||
'isVisible' => $field->isVisible, | ||||||||||
]; | ||||||||||
} | ||||||||||
|
||||||||||
return $normalized; | ||||||||||
Check failure on line 345 in src/DetailView.php
|
||||||||||
} | ||||||||||
|
||||||||||
private function renderAttributes(array|Closure $attributes): array | ||||||||||
|
@@ -371,23 +372,25 @@ | |||||||||
$rows = []; | ||||||||||
|
||||||||||
foreach ($fields as $field) { | ||||||||||
$label = strtr($this->labelTemplate, [ | ||||||||||
'{label}' => $field['label'], | ||||||||||
'{tag}' => $field['labelTag'], | ||||||||||
'{attributes}' => Html::renderTagAttributes($field['labelAttributes']), | ||||||||||
]); | ||||||||||
|
||||||||||
$value = strtr($this->valueTemplate, [ | ||||||||||
'{value}' => $field['value'], | ||||||||||
'{tag}' => $field['valueTag'], | ||||||||||
'{attributes}' => Html::renderTagAttributes($field['valueAttributes']), | ||||||||||
]); | ||||||||||
|
||||||||||
$rows[] = strtr($this->fieldTemplate, [ | ||||||||||
'{attributes}' => Html::renderTagAttributes($this->fieldAttributes), | ||||||||||
'{label}' => $label, | ||||||||||
'{value}' => $value, | ||||||||||
]); | ||||||||||
if ($field['isVisible']) { | ||||||||||
Check failure on line 375 in src/DetailView.php
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd skip the iteration instead of wrapping code. Reads a bit better.
Suggested change
|
||||||||||
$label = strtr($this->labelTemplate, [ | ||||||||||
'{label}' => $field['label'], | ||||||||||
'{tag}' => $field['labelTag'], | ||||||||||
'{attributes}' => Html::renderTagAttributes($field['labelAttributes']), | ||||||||||
]); | ||||||||||
|
||||||||||
$value = strtr($this->valueTemplate, [ | ||||||||||
'{value}' => $field['value'], | ||||||||||
'{tag}' => $field['valueTag'], | ||||||||||
'{attributes}' => Html::renderTagAttributes($field['valueAttributes']), | ||||||||||
]); | ||||||||||
|
||||||||||
$rows[] = strtr($this->fieldTemplate, [ | ||||||||||
'{attributes}' => Html::renderTagAttributes($this->fieldAttributes), | ||||||||||
'{label}' => $label, | ||||||||||
'{value}' => $value, | ||||||||||
]); | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
return implode("\n", $rows); | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -46,6 +46,8 @@ final class DataField | |||||
* | ||||||
* @param bool $encodeValue Whether the value is HTML encoded | ||||||
* | ||||||
* @param bool $isVisible Whether the field is visible | ||||||
* | ||||||
* @template TData as array|object | ||||||
* @psalm-param string|Stringable|int|float|(Closure(TData): string)|null $value | ||||||
*/ | ||||||
|
@@ -58,6 +60,7 @@ public function __construct( | |||||
public readonly string $valueTag = '', | ||||||
public readonly array|Closure $valueAttributes = [], | ||||||
public readonly bool $encodeValue = true, | ||||||
public readonly bool $isVisible = true, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
For consistency with parameter |
||||||
) { | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can skip field already here and don't add it to
$normalized
.