Augment tags from text field in GraphQL/REST API

Aperta
#7,041 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
graphql, laravel, php

Direzione di ricerca

Start by reading the GraphQL and REST API entry points that serialize text fields, then compare their behavior with Antlers template rendering and how custom tags are evaluated. The issue does not name files or tests, so first locate those paths and check for existing coverage. Done means tag expressions in text fields are handled consistently in API responses, with tests covering the reported example.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

api graphql headless
Bug description

I have a text field with this in

Random {{ custom:wrap text="nonsense" }} news in your inbox. Once a month.

and a custom tag set up like this:

<?php

namespace App\Tags;

use Statamic\Tags\Tags;

class Custom extends Tags
{
    /**
     * The {{ custom:wrap text="Title text" }} tag
     *
     * @return string|array
     */
    public function wrap()
    {
        $text = $this->params->get('text', null);
        $random_int = random_int(1, 7);
        $length_class = "sketch-short sketch-short--" . $random_int;

        if (strlen($text) > 8) {
            $random_int = random_int(1, 2);
            $length_class = "sketch-long sketch-long--" . $random_int;
        }

        return '<span class="sketch ' . $length_class . '">' . $text . '</span>';
    }
}

When outputting the value in an antlers template it gets evaluated, but in the REST API or GraphQL it just returns the plain string.

Could a custom GraphQL middleware solve this?

How to reproduce
  • Set up custom Tag
  • use tag in regular text field
  • query with graphql or rest api
Logs

No response

Environment
Environment
Application Name: Statamic
Laravel Version: 9.39.0
PHP Version: 8.1.11
Composer Version: 2.4.3
Environment: local
Debug Mode: ENABLED
URL: asdf.test
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 0
Antlers: regex
Version: 3.3.54 PRO
Installation

Fresh statamic/statamic site via CLI

Antlers Parser

runtime (new)

Additional details

No response

Lingua principale
PHP
Stelle
4.9k
Fork
647
Merge medio
1g 45m
PR unite (30g)
221

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di statamic/cms

Tutte le issue di statamic/cms

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.