2
votes

i am having trouble to sort my admin-generator-list by a i18n field.

Has someone a snippet for me to use ? The field to sort by is name

the schema.yml is:

...
        product:
      actAs:
        I18n:
          fields: [name, description]
      columns:
        product_typ_id: integer
        name: string(255)
        description: string
        image: string(255)
        image_thumb: string(255)
      relations:
        productTyp:
          onDelete: SET NULL
...
1

1 Answers

3
votes

I used http://stereointeractive.com/blog/2011/01/08/symfony-1-4-admin-generator-sort-on-custom-column/

To make this work for symfony 1.4 with propel and an I18N column (in my case called 'name' ).

In your generator.yml add:

  • fields: name: { is_real: true }

  • list: peer_method: doSelectWithI18n

In your actions.class.php:

protected function isValidSortColumn($column)
{
  return parent::isValidSortColumn($column) || $column == 'name';
}

and:

protected function addSortCriteria($criteria)
{
    if (array(null, null) == ($sort = $this->getSort()))
    {
      return;
    }
    if($sort[0]!="name") {
        $column = MyPeer::translateFieldName($sort[0], BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
    } else {
        $column = MyI18nPeer::NAME;
    }
    if ('asc' == $sort[1])
    {
      $criteria->addAscendingOrderByColumn($column);
    }
    else
    {
      $criteria->addDescendingOrderByColumn($column);
    }
}