Skip to content

Instantly share code, notes, and snippets.

@ChVuagniaux
Last active April 25, 2018 06:44
Show Gist options
  • Save ChVuagniaux/003bb50cc1c8e08a9396f0f2bfdd15ee to your computer and use it in GitHub Desktop.
Save ChVuagniaux/003bb50cc1c8e08a9396f0f2bfdd15ee to your computer and use it in GitHub Desktop.
Add nested translated repeaters to RainLab.Pages
<?php
public function boot()
{
Event::listen('backend.form.extendFieldsBefore', function (\Backend\Widgets\Form $form) {
$isStaticPage = $form->getController() instanceof \RainLab\Pages\Controllers\Index
&& $form->model instanceof \RainLab\Pages\Classes\Page;
if ($isStaticPage && !$form->isNested) {
$fields = Yaml::parse(<<<YAML
title:
label: Title
type: text
span: full
blocks:
label: Blocks
type: repeater
prompt: Add block
form:
fields:
title:
label: Title
type: text
span: full
content:
label: Content
type: richeditor
span: full
YAML
);
$form->secondaryTabs['fields'] = [
'viewBag[sections]' => [
'tab' => 'Sections',
'type' => 'repeater',
'form' => ['fields' => $fields],
'prompt' => 'Ajouter une section',
'cssClass' => 'secondary-tab ',
],
] + $form->secondaryTabs['fields'];
$form->model->translatable[] = 'viewBag[sections]';
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment