Skip to content

Commit

Permalink
Move validator messages and custom attributes into the Step
Browse files Browse the repository at this point in the history
  • Loading branch information
erikwittek committed Oct 26, 2021
1 parent c4683db commit 6f8c408
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 32 deletions.
12 changes: 0 additions & 12 deletions src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class Field extends ArcanistField implements JsonSerializable
protected $displayCallback = null;
protected $readOnly = false;

public $messages = [];
public $customAttributes = [];

public function __construct(
public string $name,
public array $rules = ['nullable'],
Expand All @@ -34,15 +31,6 @@ public function __construct(
});
}

public function rules(array $rules, array $messages = [], array $customAttributes = []): self
{
$this->rules = $rules;
$this->messages = $messages;
$this->customAttributes = $customAttributes;

return $this;
}

public function default($default) : self
{
$this->default = $default;
Expand Down
25 changes: 5 additions & 20 deletions src/WizardStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

class WizardStep extends ArcanistStep
{
protected array $validator_messages = [];
protected array $validator_attributes = [];

public function viewData(Request $request): array
{
return collect($this->fields())->mapWithKeys(function (Field $field) {
Expand All @@ -29,31 +32,13 @@ protected function rules(): array
})->all();
}

protected function messages(): array
{
return collect($this->fields())->mapWithKeys(function (Field $field) {
return Arr::isAssoc($field->messages)
? $field->messages
: [$field->name => $field->messages];
})->all();
}

protected function customAttributes(): array
{
return collect($this->fields())->mapWithKeys(function (Field $field) {
return Arr::isAssoc($field->customAttributes)
? $field->customAttributes
: [$field->name => $field->customAttributes];
})->all();
}

public function process(Request $request): StepResult
{
$data = $this->validate(
$request,
$this->rules(),
$this->messages(),
$this->customAttributes()
$this->validator_messages,
$this->validator_attributes
);

return collect($this->fields())
Expand Down

0 comments on commit 6f8c408

Please sign in to comment.