Skip to content

Best way to have a predefined set of specific but re-orderable elements. #15639

Closed Answered by brandonkelly
thupsi asked this question in Q&A
Discussion options

You must be logged in to vote

Interesting question. It seems like building this on relation fields is probably the most flexible, though it will require you to create new sections/entries even for the simpler use cases like your gallery page sections.

I’ve just added allowAdd and allowRemove settings to element select inputs (which relation fields use internally) for Craft 5.4: 0bf41d9

With that, you could register a custom field type that extends craft\fields\Entries, and sets those two settings to false, while also populating the selected entries with any missing entries, to ensure all possible entries are always selected when viewing the field.

namespace modules\foo\fields;

use craft\base\ElementInterface;
use cra…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@thupsi
Comment options

@brandonkelly
Comment options

Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants