Skip to content

Augment tags from text field in GraphQL/REST API #7041

Open
@goellner

Description

@goellner

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions