Taitava/silverstripe-untranslatablefields

the method 'gettranslations' does not exist

Closed this issue · 7 comments

I know that this is for fields and maybe not so much gridfields and their dataobjects, but I currently receive this error:

the method 'gettranslations' does not exist

when using the module on a dataobject which holds my fields.

ERROR [User Error]: Uncaught Exception: Object->__call(): the method 'gettranslations' does not exist
on 'Dealers'
IN POST /admin/pages/edit/EditForm/field/Dealers/item/3/ItemEditForm?Locale=nl_NL
Line 739 in D:\XAMPP\htdocs\framework\core\Object.php

Source

730: default :
731: throw new Exception (
732: "Object->__call(): extra method $method is invalid on $this->class:"
733: . var_export($config, true)
734: );
735: }
736: } else {
737: // Please do not change the exception code number below.
738: $class = get_class($this);

  • 739: throw new Exception("Object->__call(): the method '$method' does not exist on '$class'", 2175
    );
    740: }
    741: }
    742:
    743: //
    --------------------------------------------------------------------------------------------------------------

    744:
    745: /**

Trace

Object->__call(getTranslations,Array)
UntranslatableFields.php:54

Dealers->getTranslations()
UntranslatableFields.php:54

UntranslatableFieldsExtension->onAfterWrite(,,,,,,)
Object.php:978

Object->extend(onAfterWrite,)
DataObject.php:1115

DataObject->onAfterWrite()
DataObject.php:1393

DataObject->write()
GridFieldDetailForm.php:547

GridFieldDetailForm_ItemRequest->doSave(Array,Form,SS_HTTPRequest)
Form.php:462

Form->httpSubmission(SS_HTTPRequest)
RequestHandler.php:288

RequestHandler->handleAction(SS_HTTPRequest,httpSubmission)
RequestHandler.php:200

RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
RequestHandler.php:222

RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
GridFieldDetailForm.php:102

GridFieldDetailForm->handleItem(GridField,SS_HTTPRequest)
GridField.php:963

GridField->handleRequest(SS_HTTPRequest,DataModel)
RequestHandler.php:222

RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
RequestHandler.php:222

RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
Controller.php:157

Controller->handleRequest(SS_HTTPRequest,DataModel)
LeftAndMain.php:451

LeftAndMain->handleRequest(SS_HTTPRequest,DataModel)
AdminRootController.php:93

AdminRootController->handleRequest(SS_HTTPRequest,DataModel)
Director.php:385

Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:149

Director::direct(/admin/pages/edit/EditForm/field/Dealers/item/3/ItemEditForm,DataModel)
main.php:184

Sorry, I have had not enough time to test and develop this module, so it might be quite unstable now. I'm not sure what you mean about that this module would not be for DataObjects that are managed with a GridField. The design is quite universal and simple and does not rely upon the user interface that makes changes to DataObjects. So in theory, it should work :), but there might be a bug somewhere.

I think the getTranslations() method should be provided by the Translatable module as an extension to all of the DataObjects that are configured to use Translatable as an extension. I know this is a really basic thing to ask, but I just want to make sure. Do you have this configuration in any of your yml config files?

Dealers:
  extensions:
    - Translatable

Does regular translations work without any issues if you disable or remove the untranslatablefields module?

Can you provide your Dealers class code here? You can simplify it and remove any confidential info/code from it as you wish. Also any YAML/PHP configuration regarding that class can be helpful.

Also, thank you for pointing out this issue! Testing and bug reports are always welcome as this module unfortunately is not mature yet.

I know its something stupid I'm not doing, but so far I cant put my finger on it.

It doesn't seem to copy the data from one language to another.

Does regular translations work without any issues if you disable or remove the untranslatablefields module?

Yup

I didnt have the following:

Dealers:
  extensions:
    - Translatable

But adding it didn't seem to make a difference.

DealersPage.php

<?php
class DealersPage extends Page {

    private static $has_many = array (
        'Dealers' => 'Dealers' //change to singular "Dealer"
    );

    public function getCMSFields() {

        $fields = parent::getCMSFields();
        $fields->removeFieldFromTab("Root.Main","Content");
        $fields->addFieldToTab("Root.Main", GridField::create('Dealers','Overzicht van dealers', $this->Dealers(), GridFieldConfig_RecordEditor::create())); 

        return $fields;

    }

}

class DealersPage_Controller extends Page_Controller {

}

?>

Dealers.php

<?php
class Dealers extends DataObject {

    private static $db = array (

        'Naam' => 'Varchar(256)',
        'Straat' => 'Varchar(256)',
        'Huisnummer' => 'Varchar',
        'Postcode' => 'Varchar',
        'Stad' => 'Varchar(256)',
        'Land' => 'Varchar',
        'Telefoon' => 'Varchar',
        'Website' => 'Varchar(256)',
        'Lengtegraad' => 'Decimal(9,7)',
        'Breedtegraad' => 'Decimal(9,7)'
    );

    private static $has_one = array (
        'DealersPage' => 'DealersPage' //left is relationship name right is dataobject name
    );

    static $summary_fields = array (
        'Naam' => 'Naam',
        'Straat' => 'Straat',
        'Huisnummer' => 'Huisnummer',
        'Stad' => 'Stad',
        'Land' => 'Land'
     );

    public function getCMSFields() {

        $fields = parent::getCMSFields();

        $fields->addFieldToTab('Root.Main', TextField::create('Naam'));
        $fields->addFieldToTab('Root.Main', TextField::create('Straat'));
        $fields->addFieldToTab('Root.Main', TextField::create('Huisnummer'));
        $fields->addFieldToTab('Root.Main', TextField::create('Postcode'));
        $fields->addFieldToTab('Root.Main', TextField::create('Stad'));
        $fields->addFieldToTab('Root.Main', CountryDropdownField::create('Land'));
        $fields->addFieldToTab('Root.Main', TextField::create('Telefoon')->setRightTitle('Vergeet landcode niet, bijv. +31'));
        $fields->addFieldToTab('Root.Main', TextField::create('Website'));
        $fields->addFieldToTab('Root.Main', NumericField::create('Breedtegraad')->setRightTitle('(Latitude) Achterhalen via http://www.mapseasy.com/adress-to-gps-coordinates.php'));
        $fields->addFieldToTab('Root.Main', NumericField::create('Lengtegraad')->setRightTitle('(Longitude) Achterhalen via http://www.mapseasy.com/adress-to-gps-coordinates.php'));

        return $fields;
    }

    public function getTitle() {

        return $this->Naam;

    }   

}

_config.yml

Director:
  environment_type: 'dev'

i18n:
  common_locales:
    nl_NL:
      name: Dutch
      native: Nederlands
    fr_FR:
      name: French
      native: Francais
    en_US:
      name: English
      native: English
    de_DE:
      name: German
      native: Deutsch

Dealers:
  extensions:
    - TranslatableDataObject  

untranslatablefields.yml

UntranslatableFields:
  fields:
    Dealers:
      - Naam
      - Straat
      - Huisnummer
      - Postcode
      - Stad
      - Land
      - Telefoon
      - Website
      - Breedtegraad
      - Lengtegraad
  add_attributes_to_cms:
    - data-untranslatable: yes
    - title: "This field can't be translated separately. Changes to this field are saved across all existing translations."

Ah, now I understand. Sorry, I did not know that Translatable does not work directly for pure DataObjects and that TranslatableDataObject is used for this instead.

TranslatableDataObject is designed in a different way than Translatable in that it does not create a new record for each DataObject, but instead creates new columns in the database to the tables of the translated DataObjects.

Now that I look at the documentation of the translatable-dataobjects module, it seems that you can configure which fields of your DataObject class it translates. So is it actually so that this module is actually not needed when translating DataObjects using translatable-dataobjects?

With this YAML config, you should be able to leave out all the fields you do not wish to translate:

MyDataObject:
  extensions:
    - TranslatableDataObject
  translatable_fields:
    - Content
    - Title

The above is from the readme of the translatable-dataobject module, so please refer to it's documentation for more information.

I haven't used the translatable-dataobjects module, so perhaps I'm missing out something here. The module seems to be just what I need for one of my projects, so I'm glad that it came out in this discussion. When I have time, I will spend more time on getting familiar with the translatable-dataobjects module and see if there's anything that my module could offer on top of that.

If you still think there's an issue with this module, please let me know and I will look at it again. Otherwise I will close this issue after some time.

If I remove

Dealers:
  extensions:
    - TranslatableDataObject  

The data is also not copied across languages.

I guess what I am asking is can I use the untranslatable module to copy data from the english gridfield to say the french gridfield?
So that the same data is shown in each and regardless of which language the customer is on, they see the same info on the page.
Is that something the untranslatable module can do and if so, why does my setup not work?

Thanks again.

Umm, I think you should be able to do that using this module. Then it would require you to use the Translatable module like so:

mysite/_config.php:

Dealers::add_extension('Translatable');

Personally I have had problems with using Translatable for pure DataObjects (instead of objects derived from SiteTree). At least one problem was that a databse record did not get a correct locale value (i.e. 'en_US' or 'fi_FI') when writing a dataobject in a different language than what was to site's default language. From this conversation I have finally realized that I should try the translatable-dataobjects module.

So, to summarize it, you should be able to use this module to copy the same data on specific fields across all the different gridfields, BUT you will run into other problems because the Translatable module does have issues with pure DataObjects for some reason.

If I had understood correctly, to make everything work ,you should change your data structure design so that you will use translatable-dataobjects and instead of having multiple records per Dealer (= one record per translation), your data structure would be so that one database record contains all the translations for one Dealer. Is there any issues with this kind of setup? I think the translatable-dataobjects module work so that it does not create language specific columns for those fields that you decide to omit from the translation, meaning that the same values in those fields will be displayed no matter what language you use in the gridfield.

All sorted now Taitava.

You were right, it was not to do with your module.

I was able to use the translatable-dataobjects module and create a master list which all dataobjects are saved to.
Then I can pull the master list into the template.

It was all in the readme you linked through (Under "The DataObject (Testimonial)"):
https://github.com/bummzack/translatable-dataobject/blob/master/README.md

Thanks again for everything.

Nice to hear that it is all settled now :).