wp-graphql / wp-graphql-acf

WPGraphQL for Advanced Custom Fields
https://wpgraphql.com/acf
627 stars 123 forks source link

Include HTML in attributesJSON #325

Closed ttstauss closed 1 year ago

ttstauss commented 2 years ago

Hello,

When I make the following request:

query getPage($pageId: ID!) {
  page(id: $pageId, idType: DATABASE_ID) {
    blocks {
      ... on AcfAccordionBlock {
        attributesJSON
      }
    }
  }
}

I get the following response:

{
  "id": "block_6283330e8655e",
  "name": "acf/accordion",
  "data": {
    "accordion_0_title": "Item 1",
    "_accordion_0_title": "field_6283326ff79f7",
    "accordion_0_content": "<strong>Lorem ipsum dolor</strong> <em>sit amet, consectetur adipiscing elit,</em> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Sit amet venenatis urna cursus eget nunc. Enim neque volutpat ac tincidunt vitae semper.\r\n\r\nLorem ipsum dolor sit amet consectetur. Molestie nunc non blandit massa enim. Quam lacus suspendisse faucibus interdum posuere lorem ipsum dolor sit. Habitant morbi tristique senectus et. Sapien nec sagittis aliquam malesuada bibendum arcu vitae. Pulvinar pellentesque habitant morbi tristique senectus et netus et.\r\n\r\nEt malesuada fames ac turpis egestas sed tempus urna et. Sed nisi lacus sed viverra tellus in hac habitasse. Tempor id eu nisl nunc. Suspendisse potenti nullam ac tortor vitae purus faucibus. Donec enim diam vulputate ut pharetra sit. Consequat interdum varius sit amet mattis vulputate.",
    "_accordion_0_content": "field_62833274f79f8",
    "accordion_1_title": "Item 2",
    "_accordion_1_title": "field_6283326ff79f7",
    "accordion_1_content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Sit amet venenatis urna cursus eget nunc. Enim neque volutpat ac tincidunt vitae semper. Lorem ipsum dolor sit amet consectetur. Molestie nunc non blandit massa enim. Quam lacus suspendisse faucibus interdum posuere lorem ipsum dolor sit. Habitant morbi tristique senectus et. Sapien nec sagittis aliquam malesuada bibendum arcu vitae. Pulvinar pellentesque habitant morbi tristique senectus et netus et. Et malesuada fames ac turpis egestas sed tempus urna et. Sed nisi lacus sed viverra tellus in hac habitasse. Tempor id eu nisl nunc. Suspendisse potenti nullam ac tortor vitae purus faucibus. Donec enim diam vulputate ut pharetra sit. Consequat interdum varius sit amet mattis vulputate.",
    "_accordion_1_content": "field_62833274f79f8",
    "accordion_2_title": "Item 3",
    "_accordion_2_title": "field_6283326ff79f7",
    "accordion_2_content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Sit amet venenatis urna cursus eget nunc. Enim neque volutpat ac tincidunt vitae semper. Lorem ipsum dolor sit amet consectetur. Molestie nunc non blandit massa enim. Quam lacus suspendisse faucibus interdum posuere lorem ipsum dolor sit. Habitant morbi tristique senectus et. Sapien nec sagittis aliquam malesuada bibendum arcu vitae. Pulvinar pellentesque habitant morbi tristique senectus et netus et. Et malesuada fames ac turpis egestas sed tempus urna et. Sed nisi lacus sed viverra tellus in hac habitasse. Tempor id eu nisl nunc. Suspendisse potenti nullam ac tortor vitae purus faucibus. Donec enim diam vulputate ut pharetra sit. Consequat interdum varius sit amet mattis vulputate.",
    "_accordion_2_content": "field_62833274f79f8",
    "accordion": 3,
    "_accordion": "field_628331cdf79f6"
  },
  "align": "",
  "mode": "edit"
}

The attributesJSON content (i.e. accordion_0_content) results don't include the <p>/</p> tags (other tags like <em> or <strong> do come through). This is true for both the WYSIWYG and Text Area field types (set in ACF).

Is there any way to include the <p>/</p> tags?

twentyfortysix commented 2 years ago

This is the default ACF behavior. In normal cases you need to run wpautop (https://developer.wordpress.org/reference/functions/wpautop/) function over the ACF field, should you need it. The handling of the output is left on us. Which is fair and right.

ttstauss commented 2 years ago

Hi @twentyfortysix, thanks for the information.

That's interesting. So even though the WYSIWYG editor lets a user pick Paragraph and even gives you a link at the bottom left to highlight the paragraph your cursor is currently in, the data returned is stripped of the very <P> elements that the user dictated they wanted?

Screenshot 2022-07-05 233059

I understand what you're saying about it being fair and right, but it's a bit misleading.

I'll see if I can figure out how to use wpauto.

jasonbahl commented 1 year ago

@ttstauss obviously I'm late to the party here, but I'm not sure this issue is in the right repo. WPGraphQL for ACF doesn't output an attributesJSON field?

Perhaps you meant this issue for this repo https://github.com/pristas-peter/wp-graphql-gutenberg-acf?

I'm going to close this issue as I don't believe it's intended for this repo, but if you feel it is still a valid issue, please open a new issue, reference this one, and provide clear steps to reproduce, including a JSON export of the ACF Field Group in question.