0
votes

I have a problem with internalization of doctrine objects' forms in administration. Forms worked perfectly fine, but then I added support for multiple languages.

Schema looks like this:

content:
  actAs: 
    Timestampable: ~ 
    I18n:
      fields: [title, content]
  columns:
    parent: { type: integer }
    title: { type: string(255), notnull: true, unique: true }
    slug: { type: string(255), notnull: true, unique: true }
    content: { type: string }
    link: { type: string(255) }
    ord: { type: integer }
    type: { type: integer, default: 0 }
  relations:
    content: { onDelete: CASCADE, local: parent, foreign: id }
  indexes:
    parent: { fields: [parent] }    
    slug: { fields: [slug] } 
    type: { fields: [type] }    

Admin generator:

generator:
  class: sfDoctrineGenerator
  param:
    model_class:           content
    theme:                 admin
    non_verbose_templates: true
    with_show:             false
    singular:              ~
    plural:                ~
    route_prefix:          content
    with_doctrine_route:   true
    actions_base_class:    sfActions

    config:
      actions: ~
      fields:  
        title: { is_real: false }
        typeFull: { label: Type }
      list:    
        display: [=title, typeFull]        
        sort: ord 
        max_per_page: 100 
      filter:  
        class: false
      form:    
        class: adminContentForm
      edit:    ~
      new:     ~

And finally a form:

class adminContentForm extends BasecontentForm
{
  public function configure()
  {        
    unset($this['slug'], $this['ord'], $this['created_at'], $this['updated_at']);

    $this->embedI18n(array('de', 'fr'));
    $this->widgetSchema->setLabel('de', 'Deutsch');
    $this->widgetSchema->setLabel('fr', 'French');
  }
}

I didn't change action class.

Everything works just fine when I want to create a new entry. But a strange problem occurs when I want to update an existing entry: it saves only fields in embedded i18n forms (title, content) and fields from main form stay untouched (parent, link, type).

If I delete embedding from form, it saves parent, linky and type properly. If I add embedding back, it saves only title and content.

Have you ever encountered similar problem? I'm using Symfony 1.4.17.


EDIT:

If I add this for debugging to processForm() method in actions.class.php:

var_dump($form->getValue('link'));
$content = $form->save();        
var_dump($content->getLink());
exit();

... I see that a value in a field link was properly sent, but after saving a form the value isn't saved. $form->getValue('link') returns a proper value, but $content->getLink() returns an empty string.

1
what version of symfony 1.4 do you use?What situation in other module where you use embed i18n form?Can you posy your schema, generator.yml and form config?denys281
@denys281 Yeah, sure. I added more details. I hope it helps.Pavel Linkesch
I can't remember why, but I usually use this tutorial in to handle i18n field.j0k

1 Answers

2
votes

After two days I've finally got it! The strange behavior was caused by column "content" especially by it's name that was the same as a name of the table. There was no problem if I didn't use i18n behavior. But after adding i18n everything started to act unexpectedly, but with no error message, so it took me really long time to figure it out.

So a column name mustn't be the same as a name of a table.