Gatsby/Drupal 8-使用媒体模块时获取图像(安装Acquia Lightning) [英] Gatsby / Drupal 8 - getting an image when using the media module (Acquia Lightning install)

查看:67
本文介绍了Gatsby/Drupal 8-使用媒体模块时获取图像(安装Acquia Lightning)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在标准的Drupal 8安装中,在节点上使用图像,通过GraphQL相当容易获得图像.这里有很多很好的例子: https://github.com/gatsbyjs/gatsby/tree/master/例子/using-drupal

使用Acquia Lightning安装配置文件(或者如果您只是在使用我期望的媒体模块),媒体以不同的方式添加图像,在GraphiQL中,我看到关系中的媒体字段,其中唯一的子字段是__typename

  {allNodeBlog {边缘{节点{关系{field_media {__typename}}}}}} 

我还可以查看allMediaImage(或类似图像),在其中我可以访问图像本身.我也可以在关系"中包含所有节点信息,但是我当然需要将节点数据作为主要信息.我真的不了解将查询与节点绑定在一起的最佳方法.

  {allMediaImage {边缘{节点{关系{图像 {localFile {childImageSharp {体液 {...}}}}node__blog {ID}}}}}} 

我希望我可以以其他方式创建JSON,也许可以更轻松地访问图像.否则,首先获取节点ID的方法,然后使用该方法来选择适当的媒体.任何想法

解决方案

好像已经解决了.但是我要发布答复给其他任何试图弄清这一点的人.

在Gatsby中使用Drupal节点要求您深入了解节点与媒体实体之间的关系,然后然后深入了解媒体实体与文件之间的关系.

我正在使用一个简单的Drupal 8.6.15安装,并启用了核心Media和(实验性)Media Library.并且我在 Article 内容类型中添加了一个名为 Image Asset 的媒体字段(图像参考)(我删除了常规的 Image 字段)./p>

这是我的graphql查询的样子...

  query ArticleQuery {allNodeArticle {边缘{节点{#在GatsbyJS中使用节点ID作为密钥drupal_internal__nid#访问文章的文本信息已创建(格式字符串:"DD MMMM YYYY")标题身体 {价值概括}#这是我访问图像资产字段的位置关系{field_image_asset {关系{field_media_image {localFile {childImageSharp {流体(最大宽度:1200){...盖茨比ImageSharpFluid}}}}}}}}}}} 

On a standard Drupal 8 install using images in a node its fairly easy to get the image via GraphQL. There great examples here: https://github.com/gatsbyjs/gatsby/tree/master/examples/using-drupal

With the Acquia Lightning install profile (or if you're simply using the Media module I expect) Media is adding images differently, in GraphiQL I see the media field in relationships, the only sub field within that is __typename

    {
      allNodeBlog {
        edges {
          node {
            relationships {
              field_media {
                __typename
              }
            }
          }
        }
      }
    }

I can also look at allMediaImage (or similar), in which I do have access to the images themselves. I can also all the node information in the 'relationships', But i need the node data to be the primary information of course. I don't really understand the best way to tie that query together with the nodes.

{
  allMediaImage {
    edges {
      node {
        relationships {
          image {
            localFile {
              childImageSharp {
                fluid {
                  ...
                }
              }
            }
          }
          node__blog {
            id
          }
        }
      }
    }
  }
}

I'm hoping that I can create the JSON in a different way perhaps to allow easier access to the images. Otherwise a way of getting the node id first then using that to select the appropriate media. Any ideas

解决方案

Looks like you've worked it out already. But I'm posting a response for anyone else trying to figure this out.

Using Drupal nodes with Gatsby requires you to drill into the relationships between nodes and media entities, then into the relationship between the media entities and the files.

I'm using a simple Drupal 8.6.15 install with core Media and (experimental) Media Library enabled. And I have added a media field (image reference) called Image Asset (I removed the normal Image field) to my Article content type.

This is what my graphql query looks like...

query ArticleQuery{
  allNodeArticle {
    edges {
      node {
        # Use the node ID for the key in GatsbyJS
        drupal_internal__nid
        # Access the Article's text info
        created(formatString: "DD MMMM YYYY")
        title
        body {
          value
          summary
        }
        # Here is where I access the Image Asset field
        relationships {
          field_image_asset {
            relationships {
              field_media_image {
                localFile {
                  childImageSharp {
                    fluid(maxWidth:1200) {
                      ...GatsbyImageSharpFluid
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

这篇关于Gatsby/Drupal 8-使用媒体模块时获取图像(安装Acquia Lightning)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆