Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use craft\base\Plugin as BasePlugin;
use craft\elements\Entry;
use craft\events\DefineHtmlEvent;
use craft\helpers\UrlHelper;
use craft\web\Controller;
use craft\web\View;
use fostercommerce\entrytyperules\assetbundles\entrytyperules\EntryTypeRulesAsset;
Expand Down Expand Up @@ -73,6 +74,8 @@ public function getSettingsResponse(): mixed
[
'settings' => $this->getSettings(),
'overrides' => $overrides,
'sectionsUrl' => UrlHelper::cpUrl('settings/sections'),
'entriesUrl' => UrlHelper::cpUrl('entries'),
]
);
}
Expand Down
1 change: 1 addition & 0 deletions src/assetbundles/entrytyperules/EntryTypeRulesAsset.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Entry Type Rules plugin for Craft CMS 3.x
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Entry Type Rules plugin for Craft CMS 3.x
*
Expand Down
1 change: 1 addition & 0 deletions src/config.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Entry Type Rules plugin for Craft CMS 3.x
*
Expand Down
1 change: 1 addition & 0 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Entry Type Rules plugin for Craft CMS 3.x
*
Expand Down
206 changes: 108 additions & 98 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,104 +40,114 @@
{% endfor %}

{% block content %}

{% if configOverride %}
<p class="first warning">
<span class="icon" aria-hidden="true"></span>
<span class="visually-hidden">{{ "Warning"|t('entry-type-rules') }}: </span>
{{ "The Entry Type Rules plugin settings are being overridden in the 'config/entry-type-rules.php' file."|t('entry-type-rules') }}
</p>
<hr />
{% endif %}

{{ actionInput('entry-type-rules/settings/save-settings') }}

{{ forms.hidden({
name: 'pluginHandle',
value: 'entry-type-rules'})
}}

{% for section in sections | filter(section => section.type != 'single') %}

{% if not loop.first %}<hr />{% endif %}

<section>
<h2 class="text-xl">{{ section.name ~ ' ' ~ section.type|capitalize ~ ' ' ~ "Section"|t('entry-type-rules') }}</h2>
<table class="data fullwidth collapsible">
<thead>
<tr>
<th>
<span class="nowrap">
{{ "Entry Type"|t('entry-type-rules') }}
<span class="info">{{ "The entry type and its current total entry count."|t('entry-type-rules') }}</span>
</span>
</th>
<th>
<span class="nowrap">
{{ "Limit"|t('entry-type-rules') }}
<span class="info">
{{ "Limit the number of entries for the entry type."|t('entry-type-rules') }}<br />
<em>{{ "Leave blank or set to zero to remove limits for the entry type."|t('entry-type-rules') }}</em>
</span>
</span>
</th>
<th>
<span class="nowrap">
{{ "User Groups"|t('entry-type-rules') }}
<span class="info">
{{ "Limit which user groups can add new entries for the entry type."|t('entry-type-rules') }}<br />
<em>{{ "Admin users will always be able to add new entries."|t('entry-type-rules') }}</em>
</span>
</span>
</th>
</tr>
</thead>
<tbody>
{% for entryType in section.entryTypes %}
{% set entryTypeCount = craft.entries.section(section.handle).type(entryType.handle).count %}
{% set limitValue = settings.sections[section.handle][entryType.handle].limit|default('') %}
<tr class="entryTypeRulesLimit" data-count="{{ entryTypeCount }}">
<td>
<strong>{{ entryType.name }}</strong> <i>{{ entryType.handle }}</i><br/>
<span class="entryTypeRulesLimit__count inline-block">
{{ "Entries"|t('entry-type-rules') }}: {{ entryTypeCount }}
</span>
<span class="entryTypeRulesLimit__warning inline-block ml-2 warning hidden" style="margin-top: -3px; margin-left: 5px;">
<span class="icon" aria-hidden="true"></span>
<span class="visually-hidden">{{ "Warning"|t('entry-type-rules') }}: </span>
</span>
</td>
<td>
<div class="entryTypeRulesLimit__input">
{{ forms.textField({
id: (entryType.handle ~ '_limit'),
name: ('sections[' ~ section.handle ~ ']['~ entryType.handle ~ '][limit]'),
type: 'number',
size: 5,
min: 0,
value: limitValue,
placeholder: '0',
unit: "Entries"|t('entry-type-rules'),
}) }}
</div>
</td>
<td>
{{ forms.checkboxSelectField({
id: (entryType.handle ~ '_userGroups'),
name: ('sections[' ~ section.handle ~ ']['~ entryType.handle ~ '][userGroups]'),
options: groupOptions,
showAllOption: true,
allValue: '',
values: settings.sections[section.handle][entryType.handle].userGroups|default('')
}) }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</section>

{% endfor %}
{% if sections is empty %}
<div class="zilch">
<p>{{ 'configureSections'|t('entry-type-rules', {'url' : sectionsUrl })|raw }}</p>
</div>
{% elseif not craft.entries.count() %}
<div class="zilch">
<p>{{ 'configureEntries'|t('entry-type-rules', {'url' : entriesUrl })|raw }}</p>
</div>
{% else %}

{% if configOverride %}
<p class="first warning">
<span class="icon" aria-hidden="true"></span>
<span class="visually-hidden">{{ "Warning"|t('entry-type-rules') }}: </span>
{{ "The Entry Type Rules plugin settings are being overridden in the 'config/entry-type-rules.php' file."|t('entry-type-rules') }}
</p>
<hr />
{% endif %}

{{ actionInput('entry-type-rules/settings/save-settings') }}

{{ forms.hidden({
name: 'pluginHandle',
value: 'entry-type-rules'})
}}

{% for section in sections | filter(section => section.type != 'single') %}

{% if not loop.first %}<hr />{% endif %}

<section>
<h2 class="text-xl">{{ section.name ~ ' ' ~ section.type|capitalize ~ ' ' ~ "Section"|t('entry-type-rules') }}</h2>
<table class="data fullwidth collapsible">
<thead>
<tr>
<th>
<span class="nowrap">
{{ "Entry Type"|t('entry-type-rules') }}
<span class="info">{{ "The entry type and its current total entry count."|t('entry-type-rules') }}</span>
</span>
</th>
<th>
<span class="nowrap">
{{ "Limit"|t('entry-type-rules') }}
<span class="info">
{{ "Limit the number of entries for the entry type."|t('entry-type-rules') }}<br />
<em>{{ "Leave blank or set to zero to remove limits for the entry type."|t('entry-type-rules') }}</em>
</span>
</span>
</th>
<th>
<span class="nowrap">
{{ "User Groups"|t('entry-type-rules') }}
<span class="info">
{{ "Limit which user groups can add new entries for the entry type."|t('entry-type-rules') }}<br />
<em>{{ "Admin users will always be able to add new entries."|t('entry-type-rules') }}</em>
</span>
</span>
</th>
</tr>
</thead>
<tbody>
{% for entryType in section.entryTypes %}
{% set entryTypeCount = craft.entries.section(section.handle).type(entryType.handle).count %}
{% set limitValue = settings.sections[section.handle][entryType.handle].limit|default('') %}
<tr class="entryTypeRulesLimit" data-count="{{ entryTypeCount }}">
<td>
<strong>{{ entryType.name }}</strong> <i>{{ entryType.handle }}</i><br/>
<span class="entryTypeRulesLimit__count inline-block">
{{ "Entries"|t('entry-type-rules') }}: {{ entryTypeCount }}
</span>
<span class="entryTypeRulesLimit__warning inline-block ml-2 warning hidden" style="margin-top: -3px; margin-left: 5px;">
<span class="icon" aria-hidden="true"></span>
<span class="visually-hidden">{{ "Warning"|t('entry-type-rules') }}: </span>
</span>
</td>
<td>
<div class="entryTypeRulesLimit__input">
{{ forms.textField({
id: (entryType.handle ~ '_limit'),
name: ('sections[' ~ section.handle ~ ']['~ entryType.handle ~ '][limit]'),
type: 'number',
size: 5,
min: 0,
value: limitValue,
placeholder: '0',
unit: "Entries"|t('entry-type-rules'),
}) }}
</div>
</td>
<td>
{{ forms.checkboxSelectField({
id: (entryType.handle ~ '_userGroups'),
name: ('sections[' ~ section.handle ~ ']['~ entryType.handle ~ '][userGroups]'),
options: groupOptions,
showAllOption: true,
allValue: '',
values: settings.sections[section.handle][entryType.handle].userGroups|default('')
}) }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</section>

{% endfor %}
{% endif %}

{% endblock %}

Expand Down
3 changes: 3 additions & 0 deletions src/translations/en/entry-type-rules.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Entry Type Rules plugin for Craft CMS 3.x
*
Expand Down Expand Up @@ -38,4 +39,6 @@
'Limit which user groups can add new entries for the entry type.' => 'Limit which user groups can add new entries for the entry type.',
'Admin users will always be able to add new entries.' => 'Admin users will always be able to add new entries.',
'Entries' => 'Entries',
'configureSections' => 'You need to <a href="{url}">configure some Sections</a> first.',
'configureEntries' => 'You need to create some <a href="{url}">entries</a> first.</p>',
];
Loading