Steps to reproduce
1. fresh Drupal install
2. add a Name field to user account settings
3. add description to name field
4. visit /user/add or /user/*/edit & get WSOD
Log says
Fatal error:
Cannot use object of type Drupal\\name\\Plugin\\Field\\FieldWidget\\NameWidget as array in .../name.module on line 451
the problem code is
if (!$field || $field['cardinality'] != 1) {
$element['_description'] = array(
'#value' => '<div class="clearfix description">' . $element['#description'] . '</div>',
);
....
}
I don't understand what that if() block is doing, and removed it from my installation.
Comments
Comment #2
john_b commentedComment #3
thenchev commentedA looked into this a just removing the cardinality check works for me. Tested it out with different cardinality settings. So wanted to make a test coverage too but then i got some schema errors:
[01-Apr-2016 20:21:17 Australia/Sydney] Uncaught PHP Exception Drupal\Core\Config\Schema\SchemaIncompleteException: "Schema errors for field.field.node.page.field_name_test with the following errors: field.field.node.page.field_name_test:default_value.0.title missing schema, field.field.node.page.field_name_test:default_value.0.given missing schema, field.field.node.page.field_name_test:default_value.0.middle missing schema, field.field.node.page.field_name_test:default_value.0.family missing schema, field.field.node.page.field_name_test:default_value.0.generational missing schema, field.field.node.page.field_name_test:default_value.0.credentials missing schema" at /var/www/html/d8/core/lib/Drupal/Core/Config/Testing/ConfigSchemaChecker.php line 98looks like a followup to me.
Comment #5
alan d. commentedWithout the check is the description repeated on every element? I think that was the reason for this check.
If not, all good, if so then (without doing any D8 programming yet) isn't $field simply an object, so $field->getCardinalityOrWhateverTheFunctionIsCalled() should work?
Comment #6
thenchev commentedBy manual testing no duplicate without the check. So all fine :)
the obj is Drupal\name\Plugin\Field\FieldWidget\NameWidget i will have to see how to best get the cardinality.
Comment #7
alan d. commentedCool, but quick clean up maybe.
Late here, but thinking that with this change all we are left with is if the element has a description, render that afterwards if it is a Name Element (as opposed to a Field Widget).
Luckily this saves bridging into the field storage definition; actually a bit surprised you have to do something like this:
Comment #8
thenchev commentedDone the cleanup, also improved test to check that the description is unique.
Still remains to check the schema errors. Maybe some idea?
Comment #10
alan d. commentedWebflo, any comments on that?
Comment #11
berdirWell, simple enough, the value schema is missing :)
See field.value.string for example in core.data_types.schema.yml.
Comment #12
thenchev commentedThanks for the help.
This should make the test pass and add all missing schema.
Comment #14
webflo commentedThanks!
Comment #15
john_b commentedThanks indeed :-)
Comment #16
thenchev commentedLooks like i missed some schema last time. Right now im getting some schema errors when I use a exported view. Really sorry I'm reopening this but its just a small fix i don't think we need to open a new issue.
Comment #17
mbovan commentedLooks fine. This is related to #2691491: Add name field to the contact entity
Comment #18
webflo commentedPatch looks good, but the is no markup default setting in NameFormatter::defaultSettings. Can you fix the defaultSettings? Thanks!
Comment #19
thenchev commentedUpdated the NameFormatter::defaultSettings
Comment #20
mbovan commentedRTBC.
Comment #21
webflo commentedMarkup is a checkbox, i think boolean fits better in this case.
Comment #22
webflo commented