Required Fields, Content from Database Kirby 3.6.4

Hi,

I basically followed this guide

to create Pages from a database.
With the Update to 3.6.3 to 3.6.4 one problem occurs:
Fields that are required:true somehow aren’t proper recognized anymore. I cannot publish pages, it gives me the exception that the required fields have no content - but they do.
There is field-content in the database, and if i dump $page->children() method, there is data in the fields too. I don’t use any status-hooks.
I read 3.6.4’s changelog but can’t quite figure it out. Everything was working perfect with Kirby 3.6.3

Any Idea? Thanks in advance!

Could you please post your content model and the blueprint?

The model

class ArticlesPage extends Kirby\Cms\Page

{
    private function selectFromDb(string $dbTable, string $template):array {
        
        $data = [];
        
        foreach (Db::select($dbTable) as $item) {
            $data[] = [
                'slug'     => $item->slug(),
                'num'      => $item->status() === 'listed' ? 0 : null,
                'template' => $template,
                'model'    => $template,
                'content'  => [
                    'status'               => $item->status() === 'listed' ? 'listed': 'draft',
                    'title'                => $item->title(),
                    'subtitle'             => $item->subtitle(),
                ]
            ];
        }
        return $data;

    }
    
    public function children()
    {        
      return Pages::factory($this->selectFromDb('articles', 'article'), $this);
    }
    
    public function drafts()
    {        
      return Pages::factory($this->selectFromDb('articles', 'article'), $this);
    }

}

The Blueprint (shortened)

num: zero 
columns:
  - width: 2/3
    
    sections:
      Texts:
        type: fields
        fields:
          subtitle:
            type: text
            required: true

The subtitle is saved in the database, still i cannot change the status of the page.

What do you have in the blueprint options?

options: 
  preview: false
  changeSlug: false
  read:
    editor: false
    admin: true

Edit: While debugging, I realized that this behaviour started with v3.6.4 not 3.7.
I updated the post accordingly. Maybe things become a little clearer now ? Thanks

Hm, I don’t really see any changes in 3.6.4 that look like they could be causing this.

But what I find a bit strange is that children and drafts are the same in your model.

Thank you so much for looking into this.
I installed a completely fresh copy with none of my plugins, model adjustments etc.
I exactly followed your guide mentioned above. It’s working fine in 3.6.3. But if i upgrade to 3.6.4 (and above) any required field gets not recognized and the panel doesn’t let me publish the page. Though the field gets saved in the db.

Even if i hardcode the value from any required field in the model - the panel still behaves as if there is no data in it.

class CommentsPage extends Kirby\Cms\Page
{
    public function children()
    {
        $comments = [];

        foreach (Db::select('comments') as $comment) {

            $comments[] = [
                'slug'     => $comment->slug(),
                'num'      => $comment->status() === 'listed' ? 0 : null,
                'template' => 'comment',
                'model'    => 'comment',
                'content'  => [
                    'title'  => $comment->title() ?? 'New Comment',
                    'text'   => 'SOME STRING FOR REQUIRED FIELD',
                    'user'   => $comment->user(),
                    'status' => is_null($comment->status()) ? 'draft' : $comment->status()
                ]
            ];
        }

        return Pages::factory($comments, $this);
    }
}

For test purposes i set text field to required

  text:
    label: text
    type: textarea
    maxlength: 600
    required: true

The page can’t be published. It says:

The page has errors and cannot be published

text:
Please enter something

Phew … :confused:

I’ll look into it as soon as I can…

1 Like

Ok, I just checked this with a new Plainkit and at first thought I could reproduce the issue, until I noticed that I had a wrong field name in the table. After changing that, everything worked as expected, tested with 3.7.0.2, with and without requiring the field.

Hm no, i don’t have any wrong field names. It used to work for a long time … But: In the Plainkit there are no languages activated. And it works !
If you activate languages and add any language so that your content file is renamed to eg. comments.de.txt the error occours again. If I deactivate language and delete the language its all working fine again. So it seems to be an issue with language support maybe ? Thanks for your patience !

Oh, ok, that’s a different story. How have you implemented your languages in the database and in the model,then? Your model above doesn’t have any translations?

I actually don’t have any but the default language running. I just activated languages, because i always do … I’ll deactivate the languages for now - if translations will be needed i will dig deeper in the language implementation/database topic. Btw: Is there any cookbook/guide out there ? For now i’am happy to found the cause.
Thanks for bearing with me :slight_smile: Have a good weekend !

No, there is no cookbook recipe yet, but @bvdputte VP kit might help to get you started with this: