Page field settings

Sure!

You can create a new field in site/fields/subpage/subpage.php with the following content:

<?php

class SubpageField extends PageField {

  public function input() {

    $input = parent::input();
    $input->data(array(
      'field' => 'autocomplete',
      'url'   => purl($this->model, 'field/' . $this->name . '/subpage/autocomplete/' . $this->parent())
    ));

    return $input;

  }
  
  public function routes() {

    return array(
      array(
        'pattern' => 'autocomplete/(:all)',
        'method'  => 'post',
        'action'  => function($parent) {
          $ids = page($parent)->children()->pluck('id');
          
          return response::json(array('data' => $ids));
        }
      )
    );

  }

}

You can then use this in your blueprint:

page:
  label: Page
  type: subpage
  parent: my/parent/page

Let me know if that works.


I have created a feature request issue on GitHub about integrating something like this into the core page field.

2 Likes