A Craft plugin that allows you to set rules on number of entry types in a Craft section and/or limit who can include entry type entries based on their user group.
This plugin requires Craft CMS 5.0 or later.
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require fostercommerce/entry-type-rules
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Entry Type Rules.
Entry Type Rules will allow you to restrict entry types in sections based on a count limit and/or user group. This can be useful when taking advantage of entry types for example in a structure section, where you could have a "Contact" entry type that you only want one of within a "Pages" structure section, or a "Blog Landing Page" entry type you would only like to allow certain users to be able to create.
For example, if an entry type in a section has a count limit set, and the number of entries for that entry type has been reached, when creating a new entry, the Entry Type selector field will have that entry type disabled. Likewise, if an entry type has been restricted to allow for only certain user groups to create new ones, and the current user is not in those user groups, the entry type option will also be disabled for that entry type.
Entry Type Rules can be configured from its Settings page in the control panel or, by using a config file which will override the plugins settings from those set in the control panel settings page.
In the Control Panel, go to Settings → Entry Type Rules. The control panel settings page lists out all of your structure and channel sections, and their entry types. For each entry type you can place a numerical limit on the number of entries, and/or select the users groups which can create new entries of the entry type.
The limit field allows you to set an entry limit for the entry type. Once the number of entries has reached that limit, the entry types option will be disabled in the entry edit form. If you set the limit to a number below the current number of entries of that entry type, a warning will be displayed. NOTE: The setting will still be saved regardless of the warning, its just there to inform you.
The user groups field allows you to select the user groups that can create new entries of the entry type. If a user is not in any of the specified groups, the entry types option will be disabled in the entry edit form. NOTE: Admin users are never restricted from adding entries
To configure the plugin via a config file:
- Copy the
config.php
file from thevendor/fostercommerce/entry-type-rules
directory to Craft'sconfig/
directory - Rename it to
entry-type-rules.php
- Edit the
sections
array in that file to set the sections, entry types, limits, and user groups settings.
<?php
return [
'sections' => [
// Ex. A 'Pages' structure section handle we want to set rules for entry types in it
'pages' => [
// Ex. A 'Contact Page' entry type handle with rules set to limit it to 1 entry
'contactPage' => [
'limit' => 1,
],
// Ex. A 'Blog Landing' entry type handle with rules set to limit it to 1 entry,
// and only allow the 'Site Admins' user group to create new ones
'blogLanding' => [
'limit' => 1,
'userGroups' => ['siteAdmins']
],
],
// Ex. A 'Blog' channel section handle we want to set rules for entry types in it
'blog' => [
// Ex. A 'Press Releases' entry type handle with rules to only allow the 'Content Editors'
// and 'Content Providers' user groups to create new ones for
'pressRelease' => [
'userGroups' => [
'contentEditors',
'contentProviders',
]
],
]
]
];
- In the
sections
array you include the section handles for each section. - Within those sections you include the entry type handles for each entry type you want to create rules for.
- Within the entry types you can then include rules for :
limit
- A numeric limit for the number of entries of that entry typeuserGroups
- An array of user group handles to limit who can create new entries of that entry type
The following is a list of additional features we are working on to incorporate into Entry Type Rules:
- Compatibility with Craft 4
- Include rules for entry types in structure sections based on parent entries entry type
- Include rules for entry types in sections based on different sites/languages in a Craft multi-site setup
- Provide front end methods and variables to implement entry type rules when new entries are submitted via Craft Entry Forms
- Extend native Craft user group permissions to include entry type permissions
Brought to you by Foster Commerce