Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy ContentType API #21697

Closed
swicken-dotcms opened this issue Feb 10, 2022 · 12 comments · Fixed by #21729
Closed

Copy ContentType API #21697

swicken-dotcms opened this issue Feb 10, 2022 · 12 comments · Fixed by #21729

Comments

@swicken-dotcms
Copy link
Contributor

Is your feature request related to a problem? Please describe.
There are circumstances that might require the creation of many content types that share the same base fields. Creating the same fields each time adds tedium and could result in user error.

Describe the solution you'd like
There are multiple potential ways to implement this, however after some discussion we think the best solution would be to allow a Content Type to copy its initial fields from another Content Type. This would allow users to create bootstrap Content Types for a lot of default fields, or extend existing already created Content Types.

@john-thomas-dotcms
Copy link
Contributor

john-thomas-dotcms commented Feb 11, 2022

Here's another potential solution that I think would also work, and might offer some advantages: Allow users to “embed” one content type in another.

So, you could create a content type A with the common fields - including the velocity var names and layout those fields should always have - and then embed that entire content type into content type B. The embedding could be done multiple ways, though I think a new field type might be the simplest.

Some potential advantages:

  1. Changing the base (embedded) content type could potentially automatically change all the other content types that embed it.
    • If you wanted to change the shared fields with a solution that just copies the field, you'd have to manually change all content types that copied those fields.
  2. The embedded fields could be visually displayed as being grouped together, rather than showing as individual separate fields.
  3. The fields could be moved around within the "outer" content type as a block (retaining their layout in the process).
  4. The data for the fields could potentially be stored in the table as being content of the inner/embedded content type, instead of being content of the outer content type. (Possibly linked via some kind of hidden relationship).
    • A single search, then, could be made against all content which includes fields from the embedded type.
    • Operations such as delete field could then also be done on the source content type, affecting all content types that use it - with little to no change in existing logic for these operations.
    • These embedded fields could then also potentially be accessed via a single object (via Velocity, GraphQL query results, etc.) rather than as entirely separate fields. Meaning $content.embeddedGroup.varA instead of just $content.varA.
      • This, in turn, would allow embedding of fields even if the var names of those fields conflict with var names of fields already in the content type the fields are embedded into.

There are some other potential advantages this could offer, though I think the use cases are alot less common than the ones I mentioned above. In any case, another alternative to consider.

@erickgonzalez
Copy link
Contributor

Endpoint: /api/v1/contenttype/{{VAR_NAME_CONTENTTYPE_BASE}}/_copy and the Body (JSON) can receive this:

name REQUIRED
variable OPTIONAL
folder OPTIONAL
host OPTIONAL
icon OPTIONAL

e.g

/api/v1/contenttype/fileAsset/_copy

{
    "name": "File Asset Copy"
}

fmontes pushed a commit that referenced this issue Feb 18, 2022
* #21697 adding the create type from base type

* #21697 feedback and improvements

* #21697 including field variables now

* #21697 adding integration test for copy

* #21697 adding copy curl test

* #21697 adding copy curl test

* #21697 feedback done

* revert ContentType postman

* tests

Co-authored-by: Erick Gonzalez <[email protected]>
@fmontes fmontes reopened this Feb 18, 2022
@fmontes fmontes removed the Needs UI label Mar 2, 2022
@fmontes
Copy link
Member

fmontes commented Mar 2, 2022

UI in this issue: #21789

@wezell wezell changed the title Default fields for Content Type creation Copy ContentType API Mar 8, 2022
@bryanboza
Copy link
Contributor

Tested and now we the endpoint is working and we are able to clone content types, but here some improvements

  • If you don't send the name, we are returning a 500 error and null message in the response. Also multiple lines of error in the log, we need catch this exception and be clear with the error at log level.
    Here the log: https://gist.github.com/bryanboza/e9d923f19b9e14ab2c7c58114b439397

  • If you have relationship fields in the content type, we are altering the order of the fields and leave those ones at the end of the content type. We should create an exactly copy of the content type

  • We are not respecting the "host" parameter, always the copy set the same of the original one.

@bryanboza
Copy link
Contributor

bryanboza commented Mar 22, 2022

This card will need to doc:
Here the postman doc examples: https://t.ly/Ian4
This specific example is under: Copy ContentType

@jdotcms
Copy link
Contributor

jdotcms commented Apr 6, 2022

After a call with @bryanboza I am able to see this behavior
Screen Shot 2022-04-06 at 3 00 25 PM

@bryanboza
Copy link
Contributor

Also, we need to test this using MSSQL as db, I'm getting this error when I try to copy the fileAsset content type
image

Log Error: https://gist.github.com/bryanboza/240664e8451cd03e5a3929de9caeb4c0

@jdotcms
Copy link
Contributor

jdotcms commented Apr 11, 2022

PR

jdotcms added a commit that referenced this issue Apr 11, 2022
jdotcms added a commit that referenced this issue Apr 13, 2022
jdotcms added a commit that referenced this issue Apr 14, 2022
jdotcms added a commit that referenced this issue Apr 18, 2022
fmontes pushed a commit that referenced this issue Apr 18, 2022
* #21697 adding fixes to try to keep the layout

* #21697 improvement and fixed the copy

* #21697 fixing the sort order from the original content type copied

* #21697 adding a minor change

* #21697 fixing a curl test

* #21697 trying to fix again
@fmontes
Copy link
Member

fmontes commented Apr 18, 2022

As per @oidacra order is fine now.

@oidacra
Copy link
Member

oidacra commented Apr 18, 2022

Verified using docker image 22.04_4210df8_SNAPSHOT

@bryanboza
Copy link
Contributor

Fixed, tested on release-22.04 // Docker // FF

@wezell wezell closed this as completed Apr 26, 2022
jdotcms added a commit that referenced this issue Apr 26, 2022
fmontes pushed a commit that referenced this issue Apr 26, 2022
…pe (#22089)

* #21697 fix to aviod issues with the system host on cloning content type

* #21697 adding unit test
@fmontes fmontes reopened this Apr 26, 2022
@fmontes fmontes closed this as completed Apr 26, 2022
nollymar added a commit that referenced this issue May 9, 2022
* #22078 missing min idle (#22079)

* #21697 Fix to aviod issues with the system host on cloning content type (#22089)

* #21697 fix to aviod issues with the system host on cloning content type

* #21697 adding unit test

* #22065 Content API, ES Search API and Velocity viewtools needs to return the JSON not as a string

* #22097 Velocity render for block editor doesn’t support links

* #22066 Update block editor

* fire release docker image generation

* Update block editor library

* #22072 Add blockquote, codeBlock & horizontalRule vtl files (#22084)

* Renaming release to 22.05

* groupId was being ignored for uploadArchives command

* #22065 Adding new View Strategy for Story Block fields. (#22135)

* #22065 : Adding new View Strategy for Story Block fields.

This new View Strategy allows the REST Endpoints to transform the data from Story Block fields from JSON-as-String into a Map that can be rendered as an appropriate JSON object.

* #22065 : Fixing some Integration Tests

* #22065 : Fixing CURL Test

* Update starter (#22152)

* Updating core-web versions

* Publish Release

Co-authored-by: Will Ezell <[email protected]>
Co-authored-by: Jonathan <[email protected]>
Co-authored-by: Jose Castro <[email protected]>
Co-authored-by: Rafael Velazco <[email protected]>
Co-authored-by: Freddy Montes <[email protected]>
Co-authored-by: nollymar <[email protected]>
Co-authored-by: victoralfaro-dotcms <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants