To reproduce:

1. quick install the unami demo site
2. Enable/isntall layout_builder, jsonapi 2.x
3. enable layout builder for each article understand content type -> article -> display
4. edit an article and change the layout
5. access "/jsonapi/node/article/UUID"

The output below illustrates the bug:

"layout_builder__layout": [
  null,
  null
]

This probably is the core bug, and might be fixed by existing patches. Need to dig more

CommentFileSizeAuthor
#3 debug.png217.93 KBlawxen

Comments

skyredwang created an issue. See original summary.

lawxen’s picture

My reproduced steps:

  1. Install drupal8.7.x
  2. Install jsonapi2.x-dev, layout_builder
  3. Visit /admin/structure/types/manage/article/display and enable
    1. Use Layout Builder
    2. Allow each content item to have its layout customized.
  4. Add an article and set this article's layout

Ouput:

"layout_builder__layout": [
    null,
    null
]
lawxen’s picture

Similar issue with TypedData 'Any' can't be normalized to array if it stores an object
When enable "Allow each content item to have its layout customized" on article
Layout builder add a bundle field "layout_builder__layout" to article.

  protected function addSectionField($entity_type_id, $bundle, $field_name) {
    $field = FieldConfig::loadByName($entity_type_id, $bundle, $field_name);
    if (!$field) {
      $field_storage = FieldStorageConfig::loadByName($entity_type_id, $field_name);
      if (!$field_storage) {
        $field_storage = FieldStorageConfig::create([
          'entity_type' => $entity_type_id,
          'field_name' => $field_name,
          'type' => 'layout_section',
          'locked' => TRUE,
        ]);
        $field_storage->save();
      }

      $field = FieldConfig::create([
        'field_storage' => $field_storage,
        'bundle' => $bundle,
        'label' => t('Layout'),
      ]);
      $field->save();
    }
  }

The layout_section field type definition here: \Drupal\layout_builder\Plugin\Field\FieldType\LayoutSectionItem

class LayoutSectionItem extends FieldItemBase {

  /**
   * {@inheritdoc}
   */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties['section'] = DataDefinition::create('layout_section')
      ->setLabel(new TranslatableMarkup('Layout Section'))
      ->setRequired(FALSE);

    return $properties;
  }

We can see it use layout_section typed data \Drupal\layout_builder\Plugin\DataType\SectionData
Field layout_builder__layout store object value, see below image:

But this typed data "layout_section" can't be normalized if it stores an object.

lawxen’s picture

After add some code like anyNormalizer to TypedDataNormalizer
The jsonapi return :

"layout_builder__layout": [
        [
          {
            "layout_id": "layout_onecol",
            "layout_settings": [],
            "components": {
              "fa860f85-753a-4206-be70-03e0550891d6": {
                "uuid": "fa860f85-753a-4206-be70-03e0550891d6",
                "region": "content",
                "configuration": {
                  "id": "field_block:node:article:changed",
                  "label": "Changed",
                  "provider": "layout_builder",
                  "label_display": "visible",
                  "formatter": {
                    "label": "above",
                    "type": "timestamp",
                    "settings": {
                      "date_format": "medium",
                      "custom_date_format": "",
                      "timezone": ""
                    },
                    "third_party_settings": []
                  },
                  "context_mapping": {
                    "entity": "layout_builder.entity"
                  }
                },
                "additional": [],
                "weight": 1
              },
              "5df8fddf-25e5-4001-9bd0-7cf20897fffe": {
                "uuid": "5df8fddf-25e5-4001-9bd0-7cf20897fffe",
                "region": "content",
                "configuration": {
                  "label_display": "0",
                  "context_mapping": {
                    "entity": "layout_builder.entity"
                  },
                  "id": "field_block:node:article:body",
                  "formatter": {
                    "type": "text_default",
                    "settings": [],
                    "third_party_settings": [],
                    "label": "hidden"
                  }
                },
                "additional": [],
                "weight": 0
              },
              "c0efb163-54e5-47d3-b815-be68a74a80a2": {
                "uuid": "c0efb163-54e5-47d3-b815-be68a74a80a2",
                "region": "content",
                "configuration": {
                  "label_display": "0",
                  "context_mapping": {
                    "entity": "layout_builder.entity"
                  },
                  "id": "field_block:node:article:field_tags",
                  "formatter": {
                    "type": "entity_reference_label",
                    "label": "above",
                    "settings": {
                      "link": true
                    },
                    "third_party_settings": []
                  }
                },
                "additional": [],
                "weight": 2
              }
            }
          }
        ],
        [
          {
            "layout_id": "layout_onecol",
            "layout_settings": [],
            "components": {
              "0dd4b4e5-175d-4c66-b0c6-381f097c43e9": {
                "uuid": "0dd4b4e5-175d-4c66-b0c6-381f097c43e9",
                "region": "content",
                "configuration": {
                  "label_display": "0",
                  "context_mapping": {
                    "entity": "layout_builder.entity"
                  },
                  "id": "field_block:node:article:field_image",
                  "formatter": {
                    "type": "image",
                    "settings": {
                      "image_style": "large",
                      "image_link": ""
                    },
                    "third_party_settings": [],
                    "label": "hidden"
                  }
                },
                "additional": [],
                "weight": 0
              },
              "cb54c86f-218e-4243-8a2c-901823ebf81d": {
                "uuid": "cb54c86f-218e-4243-8a2c-901823ebf81d",
                "region": "content",
                "configuration": {
                  "label_display": "0",
                  "context_mapping": {
                    "entity": "layout_builder.entity"
                  },
                  "id": "extra_field_block:node:article:links"
                },
                "additional": [],
                "weight": 3
              },
              "06dbc3f2-a509-42ee-94a4-1bfdafa61017": {
                "uuid": "06dbc3f2-a509-42ee-94a4-1bfdafa61017",
                "region": "content",
                "configuration": {
                  "label_display": "0",
                  "context_mapping": {
                    "entity": "layout_builder.entity"
                  },
                  "id": "field_block:node:article:comment",
                  "formatter": {
                    "type": "comment_default",
                    "label": "above",
                    "settings": {
                      "view_mode": "default",
                      "pager_id": 0
                    },
                    "third_party_settings": []
                  }
                },
                "additional": [],
                "weight": 4
              }
            }
          }
        ]
      ]
lawxen’s picture

Title: JSONAPI 2.x cannot serialize layout_builder » Typed data layout_section can't be normalized if it stores object
Project: JSON:API » Layout Builder
Version: 8.x-2.x-dev »
lawxen’s picture

Project: Layout Builder » Drupal core
Version: » 8.7.x-dev
Component: Code » serialization.module
tim.plunkett’s picture

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative

This came up as the daily BSI target

I tried following the steps but I'm not seeing the error. Can you verify if you are seeing it in D11 still? If not we can close out
If still a bug please move back to Active and update the summary.

Thanks.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Since there's been no follow up and can't reproduce going to close out. If still an issue please re-open maybe updating summary with clearer steps?

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.