Augment tags from text field in GraphQL/REST API

Abierto
#7,041 5 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
graphql, laravel, php

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
PHP
Estrellas
4.9k
Forks
647
Merge medio
1 d 45 min
PR fusionados (30 d)
221

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de statamic/cms

Todos los issues de statamic/cms

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.