tractorcow-farm / silverstripe-fluent

Multi-language translate module for Silverstripe, without having to manage separate site trees.
BSD 3-Clause "New" or "Revised" License
93 stars 111 forks source link

[DataObject] Error: FieldList Root tab didn't exists #386

Open ghost opened 6 years ago

ghost commented 6 years ago

Hi everyone,

I'm integrating this module on my SS 4.0.3 project. It currently got 2 langs. I'm trying to follow the docs to configure has-many dataobjects in relation to their respective pages. Here's my project.yml:

[...]
---
  Name: traduzioni
---
# DataObject 1
Caso:
  extensions:
    - 'TractorCow\Fluent\Extension\FluentExtension'
    - 'TractorCow\Fluent\Extension\FluentFilteredExtension'
# DataObject 2
Reference:
  extensions:
    - 'TractorCow\Fluent\Extension\FluentExtension'
    - 'TractorCow\Fluent\Extension\FluentFilteredExtension'

In Reference.php:

[...]
private static $translate = [
        'Autore',
        'Titolo',
        'Azienda',
        'Commento'
   ];
[...]

    public function getCMSfields()
    {
       [...]
        $fields = FieldList::create(
            TextField::create('Autore', 'Autore'),
            TextField::create('Titolo', 'Titolo'),
            TextField::create('Azienda', 'Azienda'),
            $uploadLogo, // A GridField previously istanced
            TextareaField::create('Commento', 'Commento')
        );

        $this->extend('updateCMSFields', $fields);

        return $fields;
    }

in Reference page relation:

[...]
 private static $translate = [
        'References'
    ];
[...]

(Omitting Caso.php to avoid redondance - It's the same as above)

After running /dev/build?flush=all then try to re-enter DataObject edit page, an exception is thrown:

[User Error] FieldList::addFieldToTab() Tried to add a tab to object 'SilverStripe\Forms\FieldList' - 'Root' didn't exist.

I tried to explicitly set a root tab, but nothing. After numerous tries, when calling updateCMSfields(FieldList $fields) instead of getCMSfield() the code is compiled and edit the DataObject is allowed. Inside it, i see the Locale/Filterlocale tabs, but both empty. Plus, apparently no DB-splitting of data is set about those fields (if any field is filled then saved, data is copied in both locales).

Any suggestion?

Thanks in advance

ghost commented 6 years ago

Found it.

Both declaration of:

- 'TractorCow\Fluent\Extension\FluentExtension'
- 'TractorCow\Fluent\Extension\FluentFilteredExtension'

in yaml configuration, caused the issue. I followed @adder10 example on #207 and removed FluentFilteredExtension. It seems to work now.

ghost commented 6 years ago

I reopened the issue in order to submit the same bug with a little specification. I noticed that it's caused using explicitly - 'TractorCow\Fluent\Extension\FluentFilteredExtension' only, alone or in conjunction with - 'TractorCow\Fluent\Extension\FluentExtension' (still on SS 4.0.3).

benmanu commented 5 years ago

Have worked around this issue by going from:

public function getCMSFields()
{
    $fields = FieldList::create(
        // fields
    );

    $this->extend('updateCMSFields', $fields);

    return $fields;
}

to

public function getCMSFields()
{
    $fields = FieldList::create(TabSet::create('Root'));
    $fields->addFieldsToTab(
        'Root.main',
        [
            // fields
        ]
    );

    $this->extend('updateCMSFields', $fields);

    return $fields;
}

on the dataobject that was erroring