Skip to content

Commit

Permalink
Synchronizing with symfony svn
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Jousse committed May 27, 2010
1 parent 887e1c7 commit 882e021
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 57 deletions.
27 changes: 15 additions & 12 deletions lib/generator/sfModelGeneratorConfiguration.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @package symfony
* @subpackage generator
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @version SVN: $Id: sfModelGeneratorConfiguration.class.php 23898 2009-11-14 13:14:04Z bschussek $
* @version SVN: $Id: sfModelGeneratorConfiguration.class.php 29640 2010-05-27 14:59:23Z Jonathan.Wage $
*/
abstract class sfModelGeneratorConfiguration
{
Expand Down Expand Up @@ -383,19 +383,22 @@ public function getFormFields(sfForm $form, $context)
foreach ($names as $name)
{
list($name, $flag) = sfModelGeneratorConfigurationField::splitFieldWithFlag($name);
if (!isset($this->configuration[$context]['fields'][$name]))
if (isset($form[$name]))
{
$this->configuration[$context]['fields'][$name] = new sfModelGeneratorConfigurationField($name, array_merge(
isset($config['default'][$name]) ? $config['default'][$name] : array(),
isset($config['form'][$name]) ? $config['form'][$name] : array(),
isset($config[$context][$name]) ? $config[$context][$name] : array(),
array('is_real' => false, 'type' => 'Text', 'flag' => $flag)
));
if (!isset($this->configuration[$context]['fields'][$name]))
{
$this->configuration[$context]['fields'][$name] = new sfModelGeneratorConfigurationField($name, array_merge(
isset($config['default'][$name]) ? $config['default'][$name] : array(),
isset($config['form'][$name]) ? $config['form'][$name] : array(),
isset($config[$context][$name]) ? $config[$context][$name] : array(),
array('is_real' => false, 'type' => 'Text', 'flag' => $flag)
));
}

$field = $this->configuration[$context]['fields'][$name];
$field->setFlag($flag);
$fields[$fieldset][$name] = $field;
}

$field = $this->configuration[$context]['fields'][$name];
$field->setFlag($flag);
$fields[$fieldset][$name] = $field;
}
}

Expand Down
31 changes: 29 additions & 2 deletions lib/plugins/sfDoctrinePlugin/lib/form/sfFormDoctrine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @subpackage form
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
* @version SVN: $Id: sfFormDoctrine.class.php 28903 2010-03-30 21:00:43Z Jonathan.Wage $
* @version SVN: $Id: sfFormDoctrine.class.php 29643 2010-05-27 15:52:21Z Jonathan.Wage $
*/
abstract class sfFormDoctrine extends sfFormObject
{
Expand Down Expand Up @@ -84,7 +84,7 @@ public function embedI18n($cultures, $decorator = null)

if (false === $i18nObject->exists())
{
unset($i18n['id'], $i18n['lang']);
unset($i18n[$this->getI18nModelPrimaryKeyName()], $i18n[$this->getI18nModelI18nField()]);
}

$this->embedForm($culture, $i18n, $decorator);
Expand Down Expand Up @@ -224,6 +224,33 @@ public function getI18nFormClass()
return $this->getI18nModelName().'Form';
}

/**
* Returns the primary key name of the i18n model.
*
* @return string The primary key name of the i18n model
*/
public function getI18nModelPrimaryKeyName()
{
$primaryKey = $this->getObject()->getTable()->getIdentifier();

if (is_array($primaryKey))
{
throw new sfException(sprintf('The model "%s" has composite primary keys and cannot be used with i18n..', $this->getModelName()));
}

return $primaryKey;
}

/**
* Returns the i18nField name of the i18n model.
*
* @return string The i18nField name of the i18n model
*/
public function getI18nModelI18nField()
{
return $this->getObject()->getTable()->getTemplate('Doctrine_Template_I18n')->getI18n()->getOption('i18nField');
}

/**
* Updates the default values of the form with the current values of the current object.
*/
Expand Down
80 changes: 39 additions & 41 deletions lib/plugins/sfDoctrinePlugin/lib/record/sfDoctrineRecord.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @subpackage doctrine
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Jonathan H. Wage <jonwage@gmail.com>
* @version SVN: $Id: sfDoctrineRecord.class.php 29156 2010-04-14 22:22:41Z bschussek $
* @version SVN: $Id: sfDoctrineRecord.class.php 29644 2010-05-27 16:13:25Z Jonathan.Wage $
*/
abstract class sfDoctrineRecord extends Doctrine_Record
{
Expand Down Expand Up @@ -139,71 +139,69 @@ public function __toString()
*/
public function __call($method, $arguments)
{
$failed = false;
try {
// Try to use parent Doctrine_Record::__call() first of all
try
{
return parent::__call($method, $arguments);
}
catch (Doctrine_Record_UnknownPropertyException $de) {}

// Try to make some Symfony-specific assumptions
try
{
if (in_array($verb = substr($method, 0, 3), array('set', 'get')))
{
$table = $this->getTable();

$name = substr($method, 3);

$table = $this->getTable();
if ($table->hasRelation($name))
{
$entityName = $name;
}
else if ($table->hasField($fieldName = $table->getFieldName($name)))
{
$entityNameLower = strtolower($fieldName);
if ($table->hasField($entityNameLower))
{
$entityName = $entityNameLower;
} else {
$entityName = $fieldName;
}
$fieldNameLowered = strtolower($fieldName);
$entityName = ($table->hasField($fieldNameLowered)) ? $fieldNameLowered : $fieldName;
}
else
{
$underScored = $table->getFieldName(sfInflector::underscore($name));
if ($table->hasField($underScored) || $table->hasRelation($underScored))
$fieldNameUnderscored = $table->getFieldName(sfInflector::underscore($name));
$nameLowered = strtolower($name);

if ($table->hasField($fieldNameUnderscored) || $table->hasRelation($fieldNameUnderscored))
{
$entityName = $fieldNameUnderscored;
}
else if ($table->hasField($nameLowered) || $table->hasRelation($nameLowered))
{
$entityName = $underScored;
} else if ($table->hasField(strtolower($name)) || $table->hasRelation(strtolower($name))) {
$entityName = strtolower($name);
} else {
$camelCase = $table->getFieldName(sfInflector::camelize($name));
$camelCase = strtolower($camelCase[0]).substr($camelCase, 1, strlen($camelCase));
if ($table->hasField($camelCase) || $table->hasRelation($camelCase))
{
$entityName = $camelCase;
} else {
$entityName = $underScored;
}
$entityName = $nameLowered;
}
else
{
$fieldNameCamelized = $table->getFieldName(sfInflector::camelize($name));
$fieldNameCamelized = strtolower($fieldNameCamelized[0]) . substr($fieldNameCamelized, 1, strlen($fieldNameCamelized));
$entityName = ($table->hasField($fieldNameCamelized) || $table->hasRelation($fieldNameCamelized)) ? $fieldNameCamelized : $fieldNameUnderscored;
}
}

return call_user_func_array(
array($this, $verb),
array_merge(array($entityName), $arguments)
);
} else {
$failed = true;
}
} catch (Exception $e) {
$failed = true;
} catch (Exception $se) {}

// Re-throw exception, if any
if (isset($se) && $se)
{
throw $se;
}
if ($failed)
else if (isset($de) && $de)
{
try
{
return parent::__call($method, $arguments);
} catch (Doctrine_Record_UnknownPropertyException $e2) {}

if (isset($e) && $e)
{
throw $e;
} else if (isset($e2) && $e2) {
throw $e2;
}
throw $de;
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/sfDoctrinePlugin/web/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
margin-right: 10px;
}

#sf_admin_container ul li a
#sf_admin_container ul.sf_admin_actions li a
{
padding-left: 20px;
background: url(../images/default.png) no-repeat 0 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/sfPropelPlugin/web/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
margin-right: 10px;
}

#sf_admin_container ul li a
#sf_admin_container ul.sf_admin_actions li a
{
padding-left: 20px;
background: url(../images/default.png) no-repeat 0 0;
Expand Down

0 comments on commit 882e021

Please sign in to comment.