Skip to content
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

[4.x] Supply field's config and form's handle to extraRenderableFieldData method #8849

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Fields/Fieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public function toQueryableValue($value)
return $value;
}

public function extraRenderableFieldData(): array
public function extraRenderableFieldData($config = [], $form = null): array
{
return [];
}
Expand Down
11 changes: 10 additions & 1 deletion src/Forms/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ public function create()
$jsDriver = $this->parseJsParamDriverAndOptions($this->params->get('js'), $form);

$data['sections'] = $this->getSections($this->sessionHandle(), $jsDriver);
$data['fields'] = $this->getFields($this->sessionHandle(), $jsDriver);
if (! empty($data['sections'])) {
// fields have already been rendered in the sections: get from the sections to avoid a re-render
$data['fields'] = collect($data['sections'])->map(fn ($section) => $section['fields'])
->flatten(1)
->values()
->all();
} else {
// render fields directly
$data['fields'] = $this->getFields($this->sessionHandle(), $jsDriver);
}
$data['honeypot'] = $form->honeypot();

if ($jsDriver) {
Expand Down
2 changes: 1 addition & 1 deletion src/Tags/Concerns/RendersForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function getRenderableField($field, $errorBag = 'default', $manipulate
'default' => $field->value() ?? $field->defaultValue(),
'old' => old($field->handle()),
'value' => $value,
], $field->fieldtype()->extraRenderableFieldData());
], $field->fieldtype()->extraRenderableFieldData($field->config(), method_exists($this, 'form') ? $this->form()->handle() : null));

if ($manipulateDataCallback instanceof Closure) {
$data = $manipulateDataCallback($data, $field);
Expand Down