如何在restful post API drupal 8中发送链接和链接文本?

时间:2017-07-03 16:57:23

标签: drupal drupal-modules drupal-8

我可以使用

发送链接

" field_link":{       " href":" http://www.news24headlines.com"   },

但无法发送链接文字。我无法找到任何关于此的文档。

1 个答案:

答案 0 :(得分:0)

您可以发送标题如下的链接:

        let body = {
          _links: {
            type: {
              href:
                "http://bo.mysite.docker.localhost/rest/type/node/candidats"
            }
          },
          title: [{ value: this.firstNameLastName }],
          field_entreprise_emploi_actuel: [{ value: this.company }],
          field_adresse_email: [{ value: this.email }],
          field_lien_linkedin: [
            {
              uri: "https://www.linkedin.com",
              title: "Linkedin",
              options: []
            }
          ],
          field_lien_github: [
            {
              uri: "https://github.com",
              title: "Github",
              options: []
            }
          ],
          field_lien_autre: [
            {
              uri: "https://gist.github.com/achraf-jeday",
              title: "Autre",
              options: []
            }
          ],
          field_pays: [{ value: this.country }],
          field_prenom_nom: [{ value: this.firstNameLastName }],
          field_telephone: [{ value: this.phone }],
          field_ville: [{ value: this.city }],
          type: [{ target_id: "candidats" }]
        };

        const username = "admin";
        const password = "admin";
        const basicAuthCredential = username + ":" + password;
        const bace64 = btoa(basicAuthCredential);
        const basic = "Basic " + bace64;
        let headers = {
          headers: {
            "Content-Type": "application/hal+json",
            "X-CSRF-Token": response.data.csrf_token,
            Authorization: basic,
            "Access-Control-Allow-Origin": "http://mysite.docker.localhost",
            "Access-Control-Allow-Credentials": "true"
          }
        };
        axios.post(
            `http://bo.dhmit.docker.localhost/entity/node?_format=hal_json`,
            body,
            headers
        )
        .then(response => {
          if (response.status === 200) {
          }
        })
        .catch(e => {
          this.errors.push(e);
        });
      }
    })