Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Feature request: be able to add limit on a block type in a Matrix field #3350

Closed
bzin opened this issue Oct 5, 2018 · 12 comments
Closed

Feature request: be able to add limit on a block type in a Matrix field #3350

bzin opened this issue Oct 5, 2018 · 12 comments
Labels
enhancement improvements to existing features matrix 🕶️ features related to Matrix fields

Comments

@bzin
Copy link

bzin commented Oct 5, 2018

Description

So I am using Matrix field to create data structure for twig components that stack on top of each other in a generic page. I do not want to create any limitation on the number of blocks but it would be interesting and useful to be able to set a limit also on a specific block type.

Would this be something you see being added in a future release?

Additional info

  • Craft version: Craft Pro 3.0.26.1
  • PHP version: 7.2.7
@brandonkelly
Copy link
Member

Technically this is a duplicate of #826 but I’ll close that one instead as it never received any new activity since we switched from UserVoice to GH issues.

It’s easy enough to add it, but I’d like to better understand the use case. What sort of block within a Matrix-powered page builder would need to be limited to only use X times?

@brandonkelly brandonkelly added enhancement improvements to existing features matrix 🕶️ features related to Matrix fields labels Oct 6, 2018
@richardcalahan
Copy link

richardcalahan commented Oct 7, 2018

Often times I'll use a matrix field to build a modular page. Each matrix block is a module, and the module types would include: hero, image + copy, video, map, etc.

"Hero" or "Map" might only make sense to be included in the page once, but still orderable within all modules.

@bzin
Copy link
Author

bzin commented Oct 8, 2018

My usage case is much like @richardcalahan is saying, with the difference that I also use Matrix to use custom (twig) components, let's say you have Header, Banner, Social Feed, Text + Media, etc...

Using this blocks/components, I might want to limit the usage of for the Banner and Header components, but I do not wish to have the limitation on creating the ones that are more story and content driven.

@Anubarak
Copy link
Contributor

Anubarak commented Oct 8, 2018

Another use case are social media channels. Imagine you have a channel of persons and each person should be able to insert social media links or whatever information we require (different api tokens and what not)

Of course one could argue this is better off as a separate field type but I like to use a matrix where the different block types represents different platforms and limit them via JavaScript to one since it doesn't make sense to show the Facebook icon twice next to each other in a teaser/block/header..

Matrix blocks are not always used as a page builder. It's their main purpose of course but you can use them as a simple collection container as well

@bzin
Copy link
Author

bzin commented Oct 9, 2018

That reminds another usage I give to this field. Depending on the project I might use a Matrix on a Global set to create a Menu and Footer elements. Moreover, in this Matrix, I might want to limit certain buttons, links, text, etc...

@piotrpog
Copy link

Just recently i also had situation when this would be usefull - dont need multiple sections "sign up for newsletter", but i need multiple sections "products from specific category" - for example.

@IndigoViking
Copy link

I've needed this on several occasions. We use matrix blocks for main content or homepage blocks and typically only want one of each block, or sometimes just one block of a few types.

@BridgingUnit
Copy link

Yep, could really do with this.

Some use cases I've hit recently:

Homepage with matrix with blocks (because client would like to reorder output of sections), but each block should only be displayed once.

Matrix used for Slideshow, or display of any set of same blocks (e.g. Bios etc), but where there's a block used for headline/intro first. That should only display once, but block type of slide (or bio etc) should be multiple.

Matrix used to display set of 4 panels within a page, but should only use each once. Reason being each has slightly different fields to provide content. Again, using Matrix so client can rearrange the order of them.

@narration-sd
Copy link
Contributor

Seems to want to occur to me that if you do this, it would be good to have some flexibility in what accounts for uniqueness.

Type is one factor, but a string or numeric match (make use of PHP''s looseness??) on a chosen field could be another. Thus you could assure you didn't try to make an employee bio, a product card, etc. over again, due to differing or updated information.

Likely a field opens here also of providing a facility to find duplicated blocks, remind you if you try to save them, etc....

@bzin
Copy link
Author

bzin commented Jun 21, 2019

Any idea if this will see the light of day @brandonkelly? Missing this so much! 🙏

@daltonrooney
Copy link

This can be done with MatrixMate. Invaluable plugin, IMHO. Look for the 'maxLimit' config option for each block type.

@siffring
Copy link

I could use this on a specification table for a product. Imagine a series of key/value pairs that describe specs for a product (e.g. height: 10, weight: 20, etc.).

The layout we're working with has a one column option for products with a few specs and a two column layout for products with a lot of specs.

With a block type limit I could have a block type of "column break" that can only be used once. Without the limit I'll end up creating two matrix fields for "Specs first column" and "Specs second column" which is a little less elegant.

@brandonkelly brandonkelly added this to the 4.0 milestone Nov 25, 2019
@brandonkelly brandonkelly reopened this Nov 27, 2019
@craftcms craftcms deleted a comment from bzin Nov 27, 2019
@craftcms craftcms locked and limited conversation to collaborators Jun 22, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement improvements to existing features matrix 🕶️ features related to Matrix fields
Projects
None yet
Development

No branches or pull requests

10 participants