Set default value for components that properly validates

Created on 4 December 2024, 7 months ago

Overview

Saving a page programmatically can lead to data which fails to load in the editor due to missing tree and props.

Proposed resolution

We should call setDefaultValue with

[
  'tree' => \json_encode([ComponentTreeStructure::ROOT_UUID => []]),
  'props' => '{}',
]

User interface changes

πŸ“Œ Task
Status

Active

Version

0.0

Component

Page

Created by

πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mglaman
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    STR? Test?

    We've got very thorough validation in place, so I don't see how this is possible, unless we're doing $page = Page::create(); followed by ->save() without first doing ->validate().

  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    The code was:

        $page = $this->entityTypeManager->getStorage('xb_page')->create([
          'title' => $title,
          'uuid' => $uuid,
          'path' => [['alias' => $path]],
          'status' => TRUE,
        ]);
        $page->save();
    

    Which is what a lot of developers may do, since most do not call `validate` before saving. I have a feeling people will programmatically create the entities and while technically invalid expect them to work without XB crashing.

  • Status changed to Closed: outdated 26 days ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    This has long since been fixed, and ever since πŸ“Œ [PP-1] Consider not storing the ComponentTreeStructure data type as a JSON blob Postponed looks quite different. This is obsolete :)

Production build 0.71.5 2024