Skip to content

Commit

Permalink
#21697 including field variables now
Browse files Browse the repository at this point in the history
  • Loading branch information
jdotcms committed Feb 16, 2022
1 parent 5211d43 commit 1908125
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.dotcms.contenttype.model.field.Field;
import com.dotcms.contenttype.model.field.FieldBuilder;
import com.dotcms.contenttype.model.field.FieldVariable;
import com.dotcms.contenttype.model.field.ImmutableFieldVariable;
import com.dotcms.contenttype.model.type.BaseContentType;
import com.dotcms.contenttype.model.type.ContentType;
import com.dotcms.contenttype.model.type.ContentTypeBuilder;
Expand Down Expand Up @@ -225,20 +226,30 @@ public ContentType copyFrom(final CopyContentTypeBean copyContentTypeBean) throw
final ContentType contentType = builder.build();
final ContentType newContentType = this.save(contentType);
final List<Field> currentFields = sourceContentType.fields();
final List<Field> newFields = new ArrayList<>();
final Map<String, Field> baseFieldMap = newContentType.fieldMap();

Logger.debug(this, ()->"Saving the fields for the the content type: " + copyContentTypeBean.getName()
+ ", from: " + copyContentTypeBean.getSourceContentType().variable());

for (final Field currentField : currentFields) {

newFields.add(!baseFieldMap.containsKey(currentField.variable())?
final Field newField = !baseFieldMap.containsKey(currentField.variable())?
FieldBuilder.builder(currentField).contentTypeId(newContentType.id()).id(null).build():
baseFieldMap.get(currentField.variable()));
}
baseFieldMap.get(currentField.variable());

Logger.debug(this, ()->"Saving the fields for the the content type: " + copyContentTypeBean.getName()
+ ", from: " + copyContentTypeBean.getSourceContentType().variable());
final Field savedField = APILocator.getContentTypeFieldAPI().save(newField, user);

APILocator.getContentTypeFieldAPI().saveFields(newFields, user);
final List<FieldVariable> currentFieldVariables = currentField.fieldVariables();
if (UtilMethods.isSet(currentFields)) {
for (final FieldVariable fieldVariable : currentFieldVariables) {

final FieldVariable newFieldVariable = ImmutableFieldVariable.builder().from(fieldVariable).
fieldId(savedField.id()).id(null).userId(user.getUserId()).build();

APILocator.getContentTypeFieldAPI().save(newFieldVariable, user);
}
}
}

return newContentType;
}
Expand Down

0 comments on commit 1908125

Please sign in to comment.