prismicio-community / php-kit

Community maintained development kit for Prismic and the PHP language
https://prismic.io
Other
109 stars 83 forks source link

RichText::asHtml Hyperlinks are not correctly serialized #155

Closed bestit-ewieser closed 2 years ago

bestit-ewieser commented 6 years ago

https://github.com/prismicio/php-kit/blob/5670c79a639c09b96ad9460592713fad3a7f777d/src/Prismic/Dom/RichText.php#L307

The method looks for attributes $element->data->target, $element->data->link_type and $element->data->url.

Instead the structure of $element provided by the API is the following:

/vendor/prismic/php-sdk/src/Prismic/Dom/RichText.php:315:
object(stdClass)[938]
  public 'start' => int 25
  public 'end' => int 61
  public 'type' => string 'hyperlink' (length=9)
  public 'data' => 
    object(stdClass)[939]
      public 'type' => string 'Link.web' (length=8)
      public 'value' => 
        object(stdClass)[940]
          public 'url' => string 'https://youtu.be/asdf' (length=28)
          public 'target' => string '_blank' (length=6)
c0nst4ntin commented 2 years ago

@bestit-ewieser thank you for raising this Issue. I'm currently trying to go through all the old Issues and PRs in a mission to get things back on track.

When I tried to replicate this issue everything seems to have worked. Is it possible that you are using the old V1 API? This is the API Response I got:

{
    "type": "paragraph",
    "text": "This is a Text with a target Link and a normal Link!",
    "spans": [
        {
            "start": 22,
            "end": 33,
            "type": "hyperlink",
            "data": {
                "link_type": "Web",
                "url": "https:\/\/prismic.io",
                "target": "_blank"
            }
        },
        {
            "start": 40,
            "end": 51,
            "type": "hyperlink",
            "data": {
                "link_type": "Web",
                "url": "https:\/\/prismic.io"
            }
        }
    ]
},

Please let me know if that question continues to be relevant. I'd be happy to resolve it or close it if it's not a bug anymore.

bestit-ewieser commented 2 years ago

@c0nst4ntin Thanks for your reply! This bug is not relevant for us any more since we don't use Prismic in any of our projects currently. So I closed this issue.