Show tags in same context within panel as panelfield

did search forum but did not find anything…

did someone already create a panelfield to show the result of index query by siblings of a tag? so one can see all tags that would fit current context.

since my clients page has thousands of pages of same template doing this every panel page view is maybe to slow… but i can add caching myself.

maybe @bastianallgeier can tell me how to use the autocompletion api to query these tags using $this->index.

Just to get this right: So you want to have a tags field with autocompletion but with an additonal “help box” that lists all tags that have been used in the index?

yes. sorry for being not accurate enough.

it can be an additional field unless extending the tag field makes it easier. basically i just want to know how to read the index since i do not understand panel code (yet) – like get the tags as array. i can extend an style new field myself.

Just to check, did this ever get clarified? As to displaying used tags just above the tags field? I’m about to attempt now. Would be great as a feature to be able to just drag in tags from already used ones. Either way, was wondering how to go about this not being too familiar with the panel workings? how would you get them to append into the panel…?

class TagsaltField extends TextaltField {

  public function __construct() {

    $this->icon      = 'tag';
    $this->label     = l::get('fields.tags.label', 'Tags');
    $this->index     = 'siblings';
    $this->separator = ',';
    $this->lower     = false;

  }

  public function input() {

    $input = parent::input();
    $input->addClass('input-with-tags');
    $input->data(array(
      'field'     => 'tags',
      'lowercase' => $this->lower ? 'true' : false,
      'separator' => $this->separator,
    ));

    if(isset($this->data)) {

      $input->data('url', json_encode($this->data));



    } else if($page = $this->page()) {

      $field = empty($this->field) ? $this->name() : $this->field;
      $model = is_a($this->model, 'File') ? 'file' : 'page';

      $query = array(
        'uri'       => $page->id(),
        'index'     => $this->index(),
        'field'     => $field,
        'yaml'      => $this->parentField,
        'model'     => $model,
        'separator' => $this->separator(),
        '_csrf'     => panel()->csrf(),
      );

      $input->data('url', panel()->urls()->api() . '/autocomplete/field?' . http_build_query($query));

    }

    return $input;

  }
      public function template() {

        return $this->element()
        ->append($this->label())
        ->append($this->data(?))
        ->append($this->content())
        ->append($this->counter())
        ->append($this->help());

      }
    

}

i ended up not extending the tags field but outputing cached data right below it.

to avoid indexing all pages in cms (which where 10k+ in my case) i used multiple json files containing specific sets of tags created on frontend and panel page refresh (once every hour). these json files where parsed and outputted in panel using a simple custom field.

1 Like