아래는 Contentful에서 'Trip'이라는 콘텐츠 모델을 만들기 위해 작성한 Contentful 마이그레이션입니다. 내가하고 싶은 것은 "시작일"및 "종료일"필드의 형식을 지정하는 것입니다. Contentful은 UI에서 설정할 수있는 세 가지 형식 지정 옵션을 제공합니다.
마이그레이션 파일에 형식을 지정하지 않으면 기본적으로 형식 # 3이 표시되고 형식 # 1이 필요합니다. 이 작업을 수행하는 방법에 익숙한 사람?
감사!
class CreateTrip < RevertableMigration
self.content_type_id = 'trip'
def up
with_space do |space|
# Create content model
content_type = space.content_types.create(
name: 'Trip',
id: content_type_id,
description: 'Content model for trip cards'
)
# Set validation
validation_for_country = Contentful::Management::Validation.new
validation_for_country.in = ['Bolivia','Haiti','India','Nicaragua', 'Puerto Rico', 'South Africa']
content_type.fields.create(id: 'image', name: 'Image', type: 'Link', link_type: 'Asset', required: true)
content_type.fields.create(id: 'country', name: 'Country', type: 'Symbol', required: true, validations: [validation_for_country])
content_type.fields.create(id: 'trip_details', name: 'Trip Details', type: 'Symbol')
content_type.fields.create(id: 'start_date', name: 'Start Date', type: 'Date', required: true)
content_type.fields.create(id: 'end_date', name: 'End Date', type: 'Date', required: true)
content_type.fields.create(id: 'trip_description', name: 'Trip Description', type: 'Text')
content_type.fields.create(id: 'link_url', name: 'Link URL', type: 'Symbol', required: true)
# Publish
content_type.save
content_type.publish
# Editor interface config
editor_interface = content_type.editor_interface.default
controls = editor_interface.controls
field = controls.detect { |e| e['fieldId'] == 'trip_details' }
field['settings'] = { 'helpText' => 'City, month, participant type, etc.' }
editor_interface.update(controls: controls)
editor_interface.reload
content_type.save
content_type.publish
end
end
end
contentful export
Contentful CLI를 통해 명령을 사용하여 콘텐츠 유형을 내보낼 때 JSON에서 다음과 유사한 내용을 볼 수 있습니다.
{
"fieldId": "endDate",
"settings": {
"ampm": "24",
"format": "timeZ",
"helpText": "(Optional) The date and time when the event ends..."
},
"widgetId": "datePicker"
},
{
"fieldId": "internalTitle",
"widgetId": "singleLine"
},
{
"fieldId": "startDate",
"settings": {
"ampm": "24",
"format": "timeZ",
"helpText": "The date/time when this schedule starts..."
},
"widgetId": "datePicker"
}
이제 저는 Ruby 마이그레이션 도구를 사용하지 않지만 이로 인해 설정 field['widgetId'] = 'datePicker'
및
field['settings'] = {
'format' => 'dateonly',
'helpText' => ...
}
도움이된다면 알려주세요!
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다