Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

I18n and concrete inheritance #508

Open
pimpreneil opened this Issue · 1 comment

2 participants

@pimpreneil

When using concrete inheritance with i18n, the parent's i18n fields are not updated when set from a child.

For example, if we create a table "Campain" like this:

<table name="campain" phpName="Campain">
    <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
    <column name="name" type="varchar" required="true" primaryString="true" />

    <behavior name="i18n">
        <parameter name="i18n_columns" value="name" />
    </behavior>
</table>

And a table "CampainAlert" that extends it:

<table name="campain_alert" phpName="CampainAlert" allowPkInsert="true">
    <behavior name="concrete_inheritance">
        <parameter name="extends" value="campain" />
    </behavior>
</table>

The if we create a new CampainAlert, setting the inherited "name"field, it will only update the table campain_alert_i18n and not the table campain_i18n, having for effect not to be able to access the name field value from the parent.

@kufi

I created a fix for our project in the ConcreteInheritanceParentBehavior.

I overwrote the addObjectGetSyncParent-method (copy-paste the existing method body) and added the following codesnippet to it, just before the "return $parent" line.

    $i18nBehavior = $this->getParentTable()->getBehavior('i18n');
    if($i18nBehavior != null)
    {
        $i18nColumns = preg_split('/,/', $i18nBehavior->getParameter('i18n_columns'));
        $i18nMethod = 'get'.str_replace('%PHPNAME%', $this->getTable()->getName(), $i18nBehavior->getParameter('i18n_phpname')).'s';

        $script .= "
foreach(\$this->".$i18nMethod."() as \$i18n) {
    \$translation = \$parent->getTranslation(\$i18n->getLocale());";

        foreach($i18nColumns as $column)
        {
            $script .= "
    \$translation->set".Column::generatePhpName($column)."(\$i18n->get".Column::generatePhpName($column)."());";
        }

        $script .= "
}
";
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.