Augment tags from text field in GraphQL/REST API

未關閉
#7,041 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
25/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
graphql, laravel, php

研究方向

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.

由索引模型根據 Issue 內容生成。

描述

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

主要語言
PHP
星號
4.9k
分支
647
平均合併
1 天 45 分鐘
30 天內合併 PR
221

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

statamic/cms 的其他 Issue

查看 statamic/cms 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。