Panel field to open another panel-page in show or edit mode

I might create a plugin but for now just the code. inherits page field to create a button if readonly.

usage in blueprint

myfieldname:
  label: Show or Edit
  type: openpage
  readonly: true # if true then will show button else regular page field 
  edit: true # if true then will create panel edit link else open page in new tab

site/fields/openpage/assets/style.css

input[type="openpage"].input-is-readonly {  display: none; }

site/fields/openpage/openpage.php

<?php

class OpenPageField extends PageField {

  public $edit;

  static public $assets = array(
    /*'js' => array(
      'counter.js', // TextField
    ),*/
    'css' => array(
      'style.css',
    )
  );

  public function edit() {
    return !$this->edit ? false : $this->edit;
  }

  public function open() {

    $panelPage = panel()->page($this->value);
    if(!$panelPage) return null;

    $a = new Brick('a');
    $a->addClass('btn btn-rounded ');

    $url = $panelPage->url();
    if($this->edit()) {
      $url = panel()->site()->url() . DS . 'panel' . DS . 'pages' . DS .     $panelPage->uri() . DS . 'edit';
    } else {
      $a->attr('target', '_blank');
    }
    $a->attr('href', $url);
    //$a->val($this->value());
    $a->append($panelPage->title());

    $btn = new Brick('div');
    //$btn->addClass('openpanelpage-button');
    $btn->append($a);

    return $btn;
  }

  public function content() {

    //$content = parent::content();
    $content = new Brick('div');
    $content->addClass('field-content');
    $content->append($this->input());
    if($this->readonly()) {
      $content->append($this->open());
    } else {
      $content->append($this->icon());
    }

    return $content;
  }

} // OpenPageField

one could even add limited support for autoid from @helllicht.

public function open() {

  $urlOrHash = $this->value;
  $panelPage = null; //
  if(strlen($urlOrHash) == 32) { // try autoid
    // $fieldName = c::get('autoid.name', 'autoid'); // not in panel()
    $fieldName = 'autoid'; // HARDCODED
    $filteredPages = site()->pages()->index()->filterBy($fieldName, $urlOrHash);
    if($filteredPages->count() > 0) $panelPage = $filteredPages->first();
  }
  if(!$panelPage) { // note: 'if' needed and not 'else' and not 'else if'
    $panelPage = panel()->page($urlOrHash);
  }
  if(!$panelPage) return null;
  // continue like before...