Custom field not found after updating kirby (to version 2.5.2)

Hey all!

So yesterday I decided to upgrade my old kirby version to the most recent one. However, I ran into a problem. My custom panel field is not working anymore :frowning:
I get this error (from which I concluded it can’t find/use my class):

Exception thrown with messageThe parentimages field is missing. Please add it to your installed fields or remove it from your blueprint

Somehow I am not suprised as the fields folder was already missing (which I manually added myself) when I downloaded the package. Is there some new way of doing custom fields or am I simply missing something?

Also here is my folder structure and field class:

_-- site
___-- fields
_____-- parentimages
_______-- parentimages.php

Parentimages.php:

class ParentimagesField extends BaseField {

public function __construct() {

    $this->type    = 'select';
    $this->options = array();
    $this->icon    = 'chevron-down';

}

public function options() {
    $array = array();
    foreach ($this->page()->parent()->files() as $file) {
        $array[$file->filename()] = $file->filename();
    }
    return $array;
}

public function option($value, $text, $selected = false) {
    return new Brick('option', $this->i18n($text), array(
        'value'    => $value,
        'selected' => $selected
    ));
}

public function input() {
    $select = new Brick('select');
    $select->addClass('selectbox');
    $select->attr(array(
        'name'         => $this->name(),
        'id'           => $this->id(),
        'required'     => $this->required(),
        'autocomplete' => $this->autocomplete(),
        'autofocus'    => $this->autofocus(),
        'readonly'     => $this->readonly(),
        'disabled'     => $this->disabled(),
    ));

    $default = $this->default();

    if(!$this->required()) {
        $select->append($this->option('', '', $this->value() == ''));
    }

    if($this->readonly()) {
        $select->attr('tabindex', '-1');
    }

    foreach($this->options() as $value => $text) {
        $select->append($this->option($value, $text, $this->value() == $value));
    }

    $inner = new Brick('div');
    $inner->addClass('selectbox-wrapper');
    $inner->append($select);

    $wrapper = new Brick('div');
    $wrapper->addClass('input input-with-selectbox');
    $wrapper->append($inner);

    if($this->readonly()) {
        $wrapper->addClass('input-is-readonly');
    } else {
        $wrapper->attr('data-focus', 'true');
    }

    return $wrapper;

}

public function validate() {
    return array_key_exists($this->value(), $this->options());
}

}

No, both the structure and your file look ok, but I wonder what your field is doing that a standard Kirby select field can not?

Hi Thanks for the swift reply!

The point of this class is to be able to choose a image (which is uploaded to its parent page) from a dropdown. In this case each subpage indicates a fake profile and the images for these profiles need to be able to be switched quickly, by selecting an image from a specific set of images.
Is there a standard kirby class already available for this? (In which case that would be awesome as well).

Ps. Also, to be blunt, I am quite intrigued by the fact that it does not work so I would like to know why :slight_smile:

Good question, usually it has to do with naming issues if a field is not found. If you want, you can send me the field for a quick test.

You can use the standard Kirby select field and query images from the parent page.

Sorry I don’t quite see how I should implement this (it has been a while since I last worked in Kirby, so I’m having a slow start, sorry haha :sweat_smile: )

Edit!:

Already figured it out :stuck_out_tongue:

type: select
options: query
query:
  page: ../
  fetch: images
  value: '{{filename}}'
  text: '{{filename}}'

The above code works fine.

I also figured out why my custom class was not working… My new version was simply not build yet into the distribution folder. Sorry for the bother and thanks a lot for the help!