Skip to content

Commit

Permalink
feat(input): add getInputValOptions to allow input classes to define …
Browse files Browse the repository at this point in the history
…their own set of options.
  • Loading branch information
JoelAlphonso authored and mcaskill committed Mar 5, 2024
1 parent a4a36c2 commit 8d3ce52
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,17 @@ public function escapeVal($val, array $options = [])
return $callback($val, ...$args);
}

/**
* Overridable.
* Makes it easier to pass InputVal options from children input types.
*
* @return array
**/
public function getInputValOptions(): array
{
return [];
}

/**
* @uses AbstractProperty::inputVal() Must handle string sanitization of value.
* @throws UnexpectedValueException If the value is invalid.
Expand All @@ -384,9 +395,12 @@ public function escapeVal($val, array $options = [])
public function inputVal()
{
$prop = $this->p();
$val = $prop->inputVal($this->propertyVal(), [
$val = $prop->inputVal($this->propertyVal(), array_replace(
[
'lang' => $this->lang(),
]);
],
$this->getInputValOptions()
));

if ($val === null) {
return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,12 @@ public function defaultEditorOptions()
}

/**
* Retrieve the property's value as a json encoded string.
*
* @return string
* @return array
*/
public function jsonVal()
public function getInputValOptions() : array
{
$json = $this->propertyVal();
if (!is_string($json)) {
$json = json_encode($json);
}
if (!$json || $json == 'null') {
$json = '';
}
return $json;
return [
'pretty' => false,
];
}
}
11 changes: 11 additions & 0 deletions packages/admin/src/Charcoal/Admin/Property/Input/TextareaInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use InvalidArgumentException;
use Charcoal\Admin\Property\AbstractPropertyInput;
use UnexpectedValueException;

/**
* Multi-Line Text Input Property
Expand Down Expand Up @@ -118,6 +119,16 @@ public function setMaxLength($maxLength)
return $this;
}

/**
* @return array
*/
public function getInputValOptions() : array
{
return [
'pretty' => true,
];
}

/**
* @return integer
*/
Expand Down

0 comments on commit 8d3ce52

Please sign in to comment.