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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

John_B created an issue. See original summary.

John_B’s picture

Issue summary: View changes
thenchev’s picture

Status: Active » Needs review
FileSize
2.3 KB

A 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 98

looks like a followup to me.

Status: Needs review » Needs work

The last submitted patch, 3: preview-2629910-3.patch, failed testing.

Alan D.’s picture

Without 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?

thenchev’s picture

FileSize
34.26 KB
33.46 KB

By 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.

Alan D.’s picture

Cool, 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).

  if (!empty($element['#description'])) {
    $field = isset($element['#field']) ? $element['#field'] : NULL;
    if (!$field || $field['cardinality'] != 1) {
      $element['_description'] = array(
        '#value' => '<div class="clearfix description">' . $element['#description'] . '</div>',
      );
      unset($element['#description']);
    }
  }
  if (!empty($element['#description']) && !isset($element['#field'])) {
    $element['_description'] = array(
      '#value' => '<div class="clearfix description">' . $element['#description'] . '</div>',
    );
    unset($element['#description']);
  }

Luckily this saves bridging into the field storage definition; actually a bit surprised you have to do something like this:

class NameWidget {
  public function isMultiple() {
    // For any multiple element
    return $this->fieldDefinition->getFieldStorageDefinition()->isMultiple();
    // or maybe only applicable for those with Add another enabled....
    $cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
    return $cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED;
  }
}
thenchev’s picture

Status: Needs work » Needs review
FileSize
2.54 KB
2.76 KB

Done the cleanup, also improved test to check that the description is unique.

Still remains to check the schema errors. Maybe some idea?

Status: Needs review » Needs work

The last submitted patch, 8: wsod_caused_by-2629910-8.patch, failed testing.

Alan D.’s picture

Still remains to check the schema errors

Webflo, any comments on that?

Berdir’s picture

Well, simple enough, the value schema is missing :)

See field.value.string for example in core.data_types.schema.yml.

thenchev’s picture

Status: Needs work » Needs review
FileSize
1.5 KB
4.26 KB

Thanks for the help.
This should make the test pass and add all missing schema.

  • webflo committed 10672af on 8.x-1.x authored by Denchev
    Issue #2629910 by Denchev: WSOD caused by 'description' as array
    
webflo’s picture

Status: Needs review » Fixed

Thanks!

John_B’s picture

Thanks indeed :-)

thenchev’s picture

Status: Fixed » Needs review
FileSize
605 bytes

Looks 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.

mbovan’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#2691491: Add name field to the contact entity

Looks fine. This is related to #2691491: Add name field to the contact entity

webflo’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/config/schema/name.schema.yml
@@ -385,12 +385,15 @@ field.formatter.settings.name_default:
+    markup:

Patch looks good, but the is no markup default setting in NameFormatter::defaultSettings. Can you fix the defaultSettings? Thanks!

thenchev’s picture

Status: Needs work » Needs review
FileSize
1.42 KB
848 bytes

Updated the NameFormatter::defaultSettings

mbovan’s picture

Status: Needs review » Reviewed & tested by the community

RTBC.

webflo’s picture

Markup is a checkbox, i think boolean fits better in this case.

webflo’s picture

Status: Reviewed & tested by the community » Fixed

  • webflo committed d548027 on 8.x-1.x
    Issue #2629910 by Denchev, webflo: Fix name formatter config schema
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.