Skip to main content

Image

Description

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse viverra massa in dolor lobortis lobortis. Donec nec faucibus risus, ut scelerisque urna. Morbi consectetur dui ut posuere mattis. Morbi dapibus sapien at mi semper, a mollis lacus scelerisque. Donec eu dignissim urna. Curabitur aliquam ipsum posuere tortor sodales venenatis. Integer ut laoreet mi, vitae consectetur massa.

Fields

NameTypeDefault ValueMultipleRequiredValidation
ImageReference (Image)NoYes

Nextjs Create


//Create the file
const file = await drupal.createFileResource("file--file", {
data: {
attributes: {
type: "media--image", // <-- The type of the parent resource.
field: "field_media_image", // <-- The name of the field on the parent resource.
filename: "alo.jpg",
file: await fs.readFile("img1.webp"),
},
},
}, {
withAuth: {
username: process.env.DRUPAL_USERNAME,
password: process.env.DRUPAL_PASSWORD,
},
});

//Create the media
const media = await drupal.createResource<DrupalMedia>("media--image", {
data: {
attributes: {
name: "Name for the media",
},
relationships: {
field_media_image: {
data: {
type: "file--file",
id: file.id,
},
},
},
},
}, {
withAuth: {
username: process.env.DRUPAL_USERNAME,
password: process.env.DRUPAL_PASSWORD,
},
});

//Create the Paragraph
const paragraphImage = await drupal.createResource<DrupalParagraph>("paragraph--image", {
data: {
type: 'paragraph--image',
relationships: {
field_image: {
data: {
type: 'media--image',
id: media.id,
},
},
},
},
}, {
withAuth: {
username: process.env.DRUPAL_USERNAME,
password: process.env.DRUPAL_PASSWORD,
},
});