Problem/Motivation

When we have two shs fields with the same name - one attached to the node and another attached to a paragraph we get the same default value in shs field in the paragraph as the one in the node.

Steps to reproduce

1. Create a shs field and attache it to a node type.
2. Create a paragraph type and attach to it a shs field with the same name as the one attached to the node.
3. Create a paragraph field in the node from the newly created paragraph type.

Proposed resolution

the code in src/Plugin/Field/FieldWidget/OptionsShsWidget.php:

  $field_name = $this->fieldDefinition->getName();
    $default_value = $element['#default_value'] ?: NULL;
    $user_input = $form_state->getUserInput();
    if (isset($user_input[$field_name])) {
      $default_value = $user_input[$field_name];
    }

needs to be adapted so element parents are taken into account

API changes

Data model changes

Comments

ventzie created an issue. See original summary.

ventzie’s picture

StatusFileSize
new1.32 KB
ventzie’s picture

StatusFileSize
new1.36 KB

  • ventzie authored 3fdc3c6 on 2.0.x
    Issue #3173133 by ventzie: Default value bug for same name fields
    
stborchert’s picture

Version: 8.x-1.0-alpha5 » 2.0.x-dev
Status: Active » Fixed

Sorry, I forgot to commit your changes before making changes related to another issue. So i "faked" a commit to add credits :)

Status: Fixed » Closed (fixed)

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