Structure field in created form for custom panel page

Hi there again!

Sorry to bother you but I just ran into another problem!
I am currently trying to create a custom panel page.

However, while creating the form (listed below), I get the following error:

Method StructureField::__toString() must not throw an exception, caught Error: Call to a member function structure() on null

It seems the structure field is not possible to use out of the box in my custom form. Is there any other way to create something alike or make this work?

forms/config.php:

<?php // /site/plugins/plugin-name/forms/config.php
    
    return function() {
    
      $form = new Kirby\Panel\Form(array(
        'headertitle' => array(
          'label'   => 'Plantenbeheer',
          'type'    => 'headline',
          'icon'    => 'flower'
        ),
        'plant' => array(
          'label'   => 'Plantencollectie',
          'type'    => 'structure',
          'style'   => 'table',
          'fields'  => array(
            'name'  => array(
              'label' => 'Naam',
              'type'  => 'text',
              'width' => '1/4'
            ),
            'latinname'  => array(
              'label' => 'Latijnse naam',
              'type'  => 'text',
              'width' => '1/2'
            ),
            'height'  => array(
              'label' => 'Hoogte',
              'type'  => 'number',
              'width' => '1/4'
            ),
            'colour'  => array(
              'label' => 'Kleur',
              'type'  => 'text',
              'width' => '1/2'
            ),
            'bloomingperiod'  => array(
              'label' => 'Bloeiperiode',
              'type'  => 'text',
              'width' => '1/2'
            ),
            'stock' => array(
              'label' => 'Voorraad',
              'type'  => 'number',
              'width' => '1/4'
            ),
            'price' => array(
              'label' => 'Prijs',
              'type'  => 'Number',
              'width' => '1/4',
              'icon'  => 'euro'
            ),
            'image'   => array(
              'label' => 'Plaatje',
              'type'  => 'image',
              'width' => '1/2'
            ),
            'comment'  => array(
              'label' => 'Opmerking',
              'type'  => 'text',
            ),
            'description'  => array(
              'label' => 'Beschrijving',
              'type'  => 'textarea'
            )
          )
        )
      ));
    
      $form->attr('autocomplete', 'off');
      $form->data('autosubmit', 'native');
      $form->style('centered');
      
      $form->buttons->submit->value = 'Sla wijzigingen op';
    
      return $form;
    
    };

Thanks for your help!

Is that the complete error message? No stack trace?

Yup that’s it for the useful info.
Well, it also states the error is given in debug mode at line 0 of class “brick” (which makes no sense to me as it seems to me that the error should be thrown at line 374 of the “form” class and then somewhere around line 180 in the “brick” class).

Edit:

I made a screengrab of the debugger. Hope this helps (I have no clue why it doesn’t work yet).

It seems that the structure field is not the only one that throws an error when used like this, the image field and the textarea field also throw an error.