Cannot extend existing field

Yes. The blocks and layout fields are the only fields in core that aren’t configured as an array somewhere in kirby/config/fields but instead have their own classes in kirby/src/Form/Field.
I don’t really have an explanation, but I guess the 'extends' => 'blocks' part doesn’t really work because of this.

It’s becoming hackier and hackier… But you might get it to work like this:

<?php 

use Kirby\Cms\App as Kirby;
use Kirby\Form\Field\BlocksField as BaseBlocks;

class BlocksField extends BaseBlocks {
    public function __construct(array $params = []) {
        $params['pretty'] ??= true;
        parent::__construct($params);
    }
}

Kirby::plugin('trych/blockdefaults', [
    'fields' => [
        'blocks' => '\BlocksField',
    ]
]);

Notice that your class has to be called BlocksField for the magic to work; while the fact that it’s another namespace doesn’t seem to bother Kirby… This is because for FieldClasses Kirby derives their type by default from the class name. This behavior is implemented here.
You could also write the type explicitly like this:

<?php 

use Kirby\Cms\App as Kirby;
use Kirby\Form\Field\BlocksField;

class PrettyBlocks extends BlocksField {
   public function __construct(array $params = []) {
       $params['pretty'] ??= true;
       parent::__construct($params);
   }

   public function type(): string {
       return 'blocks';
   }
}

Kirby::plugin('trych/blockdefaults', [
   'fields' => [
       'blocks' => '\PrettyBlocks',
   ]
]);
3 Likes