protected void EnhanceSelect2(JObject model, bool onlyData) { string colName = string.IsNullOrEmpty(_collection) ? "Items" : _collection; bool addDataEnhance = _manifest.AdditionalDataDefined(); if (addDataEnhance && _additionalData == null) { GetAdditionalData(onlyData); } bool collectionEnhance = _templateFiles?.Model != null && _templateFiles.Model.ContainsKey(colName); bool enhance = addDataEnhance || collectionEnhance || (_templateFiles != null && _templateFiles.LabelsInTemplate); if (enhance && (_optionsJson == null || _schemaJson == null)) { var alpaca = _ds.GetAlpaca(_dsContext, true, true, false); if (alpaca != null) { _schemaJson = alpaca["schema"] as JObject; // cache _optionsJson = alpaca["options"] as JObject; // cache } } if (enhance) { var colManifest = collectionEnhance ? _templateFiles.Model[colName] : null; var includes = colManifest?.Includes; var includelabels = _templateFiles != null && _templateFiles.LabelsInTemplate; var ds = DataSourceManager.GetDataSource(_manifest.DataSource); var dsContext = OpenContentUtils.CreateDataContext(_module); JsonUtils.LookupJson(model, _additionalData, _schemaJson, _optionsJson, includelabels, includes, (col, id) => { // collection enhancement dsContext.Collection = col; var dsItem = ds.Get(dsContext, id); if (dsItem != null && dsItem.Data is JObject) { return(dsItem.Data as JObject); } else { JObject res = new JObject(); res["Id"] = id; res["Collection"] = col; res["Title"] = "unknow"; return(res); } }, (key) => { return(ds.GetDataAlpaca(dsContext, true, true, false, key)); }); } if (_optionsJson != null) { LookupSelect2InOtherModule(model, _optionsJson, onlyData); } }