Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error on Form/Type/ModelType.php. #431

Merged
merged 1 commit into from
Oct 13, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions Form/Type/ModelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static function createChoiceLabel($choice)
{
return (string) $choice;
}

/**
* Creates the field name for a choice.
*
Expand Down Expand Up @@ -134,17 +134,17 @@ public function configureOptions(OptionsResolver $resolver)
$choiceLoader = function (Options $options) {
// Unless the choices are given explicitly, load them on demand
if (null === $options['choices']) {

$propelChoiceLoader = new PropelChoiceLoader(
$this->choiceListFactory,
$options['class'],
$options['query'],
$options['index_property']
);

return $propelChoiceLoader;
}

return null;
};

Expand Down Expand Up @@ -178,12 +178,15 @@ public function configureOptions(OptionsResolver $resolver)
$firstIdentifier = current($identifier);
if (count($identifier) === 1 && in_array($firstIdentifier->getPdoType(), [\PDO::PARAM_BOOL, \PDO::PARAM_INT, \PDO::PARAM_STR])) {
return function($object) use ($firstIdentifier) {
return call_user_func([$object, 'get' . ucfirst($firstIdentifier->getPhpName())]);
if ($object) {
return call_user_func([$object, 'get' . ucfirst($firstIdentifier->getPhpName())]);
}
return null;
};
}
return null;
};

$queryNormalizer = function (Options $options, $query) {
if ($query === null) {
$queryClass = $options['class'] . 'Query';
Expand All @@ -202,7 +205,7 @@ public function configureOptions(OptionsResolver $resolver)
}
return $query;
};

$choiceLabelNormalizer = function (Options $options, $choiceLabel) {
if ($choiceLabel === null) {
if ($options['property'] == null) {
Expand All @@ -212,16 +215,16 @@ public function configureOptions(OptionsResolver $resolver)
/** @var ModelCriteria $query */
$query = $options['query'];
$getter = 'get' . ucfirst($query->getTableMap()->getColumn($valueProperty)->getPhpName());

$choiceLabel = function($choice) use ($getter) {
return call_user_func([$choice, $getter]);
};
}
}

return $choiceLabel;
};

$resolver->setDefaults([
'query' => null,
'index_property' => null,
Expand Down