codefog / contao-haste

Haste is a collection of tools and classes to ease working with Contao
http://codefog.pl/extension/haste.html
MIT License
42 stars 24 forks source link

Fix the addFieldsFromDca() method #61

Closed qzminski closed 9 years ago

qzminski commented 9 years ago

This method should skip the fields without set "inputType" as the default use of it would result in an error, e.g. for field id or tstamp which has no input type and thus the exception will be thrown.

https://github.com/codefog/contao-haste/blob/master/library/Haste/Form/Form.php#L392

qzminski commented 9 years ago

@Toflar do you agree?

Toflar commented 9 years ago

No, you should just not pass the ones that have no inputType set. Silent skipping is always bad :)

qzminski commented 9 years ago

Then maybe we should state that in the documentation? Currently it's not really obvious and the error like Could not find class "" for type "" is not that obvious.

Toflar commented 9 years ago

I see - the message doesn't really help then. We could throw a different exception? As long as this one is also a RuntimeException it's no BC break :)

Toflar commented 9 years ago

What about this:

a)

[...]
if (!isset($arrField['type'])) {
    throw new \RuntimeException(sprintf('You did not specify any inputType for the field "%s"!', $strName));
}
[...]

b) Add a callback that filters for all the fields that have an inputType specified so you don't have to write the same code over and over again but can instead just do:

$form->addFieldsFromDca($table, $hasteBuiltInFilterCallbackName);