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

Document NavigationTabType #1756

Merged
merged 2 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions development/components/form/types-reference/navigation-tab-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,54 @@ This form type is used as a container of sub forms, each sub form will be render

| Option | Type | Default value | Description |
| :----------- | :----- | :-------------------------------- | :---------------------------------------------------------------------------------------- |

## Usage and description

This form type [was introduced in {{< minver v="8.1.0">}}](https://github.com/PrestaShop/PrestaShop/pull/28752) in the product form.
thomasnares marked this conversation as resolved.
Show resolved Hide resolved

The new Product page uses this form type as the base form type.
thomasnares marked this conversation as resolved.
Show resolved Hide resolved

Its example usage has been documented in an example module: [`demoproductform`](https://github.com/PrestaShop/example-modules/tree/master/demoproductform).
thomasnares marked this conversation as resolved.
Show resolved Hide resolved

The module hooks to `actionProductFormBuilderModifier` to modify the `FormBuilder` for the Product page.
The `ProductFormModifier` adds a new `CustomTabType` (created by the module) to the `FormBuilder` (which is a `NavigationTabType`).

```php
$this->formBuilderModifier->addAfter(
$productFormBuilder,
'pricing',
'custom_tab',
CustomTabType::class,
[
'data' => [
'custom_price' => $customProduct->custom_price,
],
]
);
```

This `CustomTabType` contains a simple form type:

```php
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add('custom_price', MoneyType::class, [
'label' => $this->trans('My custom price', 'Modules.Demoproductform.Admin'),
'label_tag_name' => 'h3',
'currency' => $this->defaultCurrency->iso_code,
'required' => false,
'constraints' => [
new NotBlank(),
new Type(['type' => 'float']),
new PositiveOrZero(),
],
])
;
}
```

It is rendered this way in the BO Product page:
thomasnares marked this conversation as resolved.
Show resolved Hide resolved

{{< figure src="../img/navigation-tab-type.png" title="NavigationTabType" >}}
Loading