@botonic/plugin-contentful
Version:
## What Does This Plugin Do?
49 lines • 2.31 kB
JavaScript
import { __awaiter } from "tslib";
import * as cms from '../../cms';
import { addCustomFields, ContentfulEntryUtils, } from '../delivery-utils';
import { DeliveryWithReference } from './reference';
// TODO does not yet load the followU p
export class CarouselDelivery extends DeliveryWithReference {
constructor(delivery, button, resumeErrors) {
super(cms.ContentType.CAROUSEL, delivery, resumeErrors);
this.button = button;
}
carousel(id, context) {
return __awaiter(this, void 0, void 0, function* () {
const entry = yield this.getEntry(id, context);
return this.fromEntry(entry, context);
});
}
fromEntry(entry, context) {
return __awaiter(this, void 0, void 0, function* () {
const elements = yield this.asyncMap(context, entry.fields.elements, (entry) => __awaiter(this, void 0, void 0, function* () {
return this.elementFromEntry(entry, context);
}));
const fields = entry.fields;
const followup = yield this.getReference().fromEntry(fields.followup, context);
const common = ContentfulEntryUtils.commonFieldsFromEntry(entry, followup);
const referenceDelivery = {
delivery: this.reference,
context,
};
return addCustomFields(new cms.Carousel(common, elements), entry.fields, referenceDelivery);
});
}
element(id, context) {
return __awaiter(this, void 0, void 0, function* () {
const entry = yield this.delivery.getEntry(id, context);
return this.elementFromEntry(entry, context);
});
}
elementFromEntry(entry, context) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
this.checkEntry(entry);
const fields = entry.fields;
const buttonEntries = fields.buttons || [];
const buttons = yield this.button.fromReferenceSkipErrors(buttonEntries, context);
return new cms.Element(entry.sys.id, buttons, (_a = fields.title) !== null && _a !== void 0 ? _a : '', (_b = fields.subtitle) !== null && _b !== void 0 ? _b : '', this.urlFromAssetOptional(fields.pic, context));
});
}
}
//# sourceMappingURL=carousel.js.map