Skip to content

Commit 910e742

Browse files
authored
Merge pull request #14 from FosterCommerce/show-message-when-no-entries
2 parents 9da2a4a + 6f3eac6 commit 910e742

File tree

7 files changed

+118
-98
lines changed

7 files changed

+118
-98
lines changed

src/Plugin.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use craft\base\Plugin as BasePlugin;
1010
use craft\elements\Entry;
1111
use craft\events\DefineHtmlEvent;
12+
use craft\helpers\UrlHelper;
1213
use craft\web\Controller;
1314
use craft\web\View;
1415
use fostercommerce\entrytyperules\assetbundles\entrytyperules\EntryTypeRulesAsset;
@@ -73,6 +74,8 @@ public function getSettingsResponse(): mixed
7374
[
7475
'settings' => $this->getSettings(),
7576
'overrides' => $overrides,
77+
'sectionsUrl' => UrlHelper::cpUrl('settings/sections'),
78+
'entriesUrl' => UrlHelper::cpUrl('entries'),
7679
]
7780
);
7881
}

src/assetbundles/entrytyperules/EntryTypeRulesAsset.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Entry Type Rules plugin for Craft CMS 3.x
45
*

src/assetbundles/entrytyperules/EntryTypeRulesSettingsAsset.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Entry Type Rules plugin for Craft CMS 3.x
45
*

src/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Entry Type Rules plugin for Craft CMS 3.x
45
*

src/controllers/DefaultController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Entry Type Rules plugin for Craft CMS 3.x
45
*

src/templates/settings.twig

Lines changed: 108 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -40,104 +40,114 @@
4040
{% endfor %}
4141

4242
{% block content %}
43-
44-
{% if configOverride %}
45-
<p class="first warning">
46-
<span class="icon" aria-hidden="true"></span>
47-
<span class="visually-hidden">{{ "Warning"|t('entry-type-rules') }}: </span>
48-
{{ "The Entry Type Rules plugin settings are being overridden in the 'config/entry-type-rules.php' file."|t('entry-type-rules') }}
49-
</p>
50-
<hr />
51-
{% endif %}
52-
53-
{{ actionInput('entry-type-rules/settings/save-settings') }}
54-
55-
{{ forms.hidden({
56-
name: 'pluginHandle',
57-
value: 'entry-type-rules'})
58-
}}
59-
60-
{% for section in sections | filter(section => section.type != 'single') %}
61-
62-
{% if not loop.first %}<hr />{% endif %}
63-
64-
<section>
65-
<h2 class="text-xl">{{ section.name ~ ' ' ~ section.type|capitalize ~ ' ' ~ "Section"|t('entry-type-rules') }}</h2>
66-
<table class="data fullwidth collapsible">
67-
<thead>
68-
<tr>
69-
<th>
70-
<span class="nowrap">
71-
{{ "Entry Type"|t('entry-type-rules') }}
72-
<span class="info">{{ "The entry type and its current total entry count."|t('entry-type-rules') }}</span>
73-
</span>
74-
</th>
75-
<th>
76-
<span class="nowrap">
77-
{{ "Limit"|t('entry-type-rules') }}
78-
<span class="info">
79-
{{ "Limit the number of entries for the entry type."|t('entry-type-rules') }}<br />
80-
<em>{{ "Leave blank or set to zero to remove limits for the entry type."|t('entry-type-rules') }}</em>
81-
</span>
82-
</span>
83-
</th>
84-
<th>
85-
<span class="nowrap">
86-
{{ "User Groups"|t('entry-type-rules') }}
87-
<span class="info">
88-
{{ "Limit which user groups can add new entries for the entry type."|t('entry-type-rules') }}<br />
89-
<em>{{ "Admin users will always be able to add new entries."|t('entry-type-rules') }}</em>
90-
</span>
91-
</span>
92-
</th>
93-
</tr>
94-
</thead>
95-
<tbody>
96-
{% for entryType in section.entryTypes %}
97-
{% set entryTypeCount = craft.entries.section(section.handle).type(entryType.handle).count %}
98-
{% set limitValue = settings.sections[section.handle][entryType.handle].limit|default('') %}
99-
<tr class="entryTypeRulesLimit" data-count="{{ entryTypeCount }}">
100-
<td>
101-
<strong>{{ entryType.name }}</strong> <i>{{ entryType.handle }}</i><br/>
102-
<span class="entryTypeRulesLimit__count inline-block">
103-
{{ "Entries"|t('entry-type-rules') }}: {{ entryTypeCount }}
104-
</span>
105-
<span class="entryTypeRulesLimit__warning inline-block ml-2 warning hidden" style="margin-top: -3px; margin-left: 5px;">
106-
<span class="icon" aria-hidden="true"></span>
107-
<span class="visually-hidden">{{ "Warning"|t('entry-type-rules') }}: </span>
108-
</span>
109-
</td>
110-
<td>
111-
<div class="entryTypeRulesLimit__input">
112-
{{ forms.textField({
113-
id: (entryType.handle ~ '_limit'),
114-
name: ('sections[' ~ section.handle ~ ']['~ entryType.handle ~ '][limit]'),
115-
type: 'number',
116-
size: 5,
117-
min: 0,
118-
value: limitValue,
119-
placeholder: '0',
120-
unit: "Entries"|t('entry-type-rules'),
121-
}) }}
122-
</div>
123-
</td>
124-
<td>
125-
{{ forms.checkboxSelectField({
126-
id: (entryType.handle ~ '_userGroups'),
127-
name: ('sections[' ~ section.handle ~ ']['~ entryType.handle ~ '][userGroups]'),
128-
options: groupOptions,
129-
showAllOption: true,
130-
allValue: '',
131-
values: settings.sections[section.handle][entryType.handle].userGroups|default('')
132-
}) }}
133-
</td>
134-
</tr>
135-
{% endfor %}
136-
</tbody>
137-
</table>
138-
</section>
139-
140-
{% endfor %}
43+
{% if sections is empty %}
44+
<div class="zilch">
45+
<p>{{ 'configureSections'|t('entry-type-rules', {'url' : sectionsUrl })|raw }}</p>
46+
</div>
47+
{% elseif not craft.entries.count() %}
48+
<div class="zilch">
49+
<p>{{ 'configureEntries'|t('entry-type-rules', {'url' : entriesUrl })|raw }}</p>
50+
</div>
51+
{% else %}
52+
53+
{% if configOverride %}
54+
<p class="first warning">
55+
<span class="icon" aria-hidden="true"></span>
56+
<span class="visually-hidden">{{ "Warning"|t('entry-type-rules') }}: </span>
57+
{{ "The Entry Type Rules plugin settings are being overridden in the 'config/entry-type-rules.php' file."|t('entry-type-rules') }}
58+
</p>
59+
<hr />
60+
{% endif %}
61+
62+
{{ actionInput('entry-type-rules/settings/save-settings') }}
63+
64+
{{ forms.hidden({
65+
name: 'pluginHandle',
66+
value: 'entry-type-rules'})
67+
}}
68+
69+
{% for section in sections | filter(section => section.type != 'single') %}
70+
71+
{% if not loop.first %}<hr />{% endif %}
72+
73+
<section>
74+
<h2 class="text-xl">{{ section.name ~ ' ' ~ section.type|capitalize ~ ' ' ~ "Section"|t('entry-type-rules') }}</h2>
75+
<table class="data fullwidth collapsible">
76+
<thead>
77+
<tr>
78+
<th>
79+
<span class="nowrap">
80+
{{ "Entry Type"|t('entry-type-rules') }}
81+
<span class="info">{{ "The entry type and its current total entry count."|t('entry-type-rules') }}</span>
82+
</span>
83+
</th>
84+
<th>
85+
<span class="nowrap">
86+
{{ "Limit"|t('entry-type-rules') }}
87+
<span class="info">
88+
{{ "Limit the number of entries for the entry type."|t('entry-type-rules') }}<br />
89+
<em>{{ "Leave blank or set to zero to remove limits for the entry type."|t('entry-type-rules') }}</em>
90+
</span>
91+
</span>
92+
</th>
93+
<th>
94+
<span class="nowrap">
95+
{{ "User Groups"|t('entry-type-rules') }}
96+
<span class="info">
97+
{{ "Limit which user groups can add new entries for the entry type."|t('entry-type-rules') }}<br />
98+
<em>{{ "Admin users will always be able to add new entries."|t('entry-type-rules') }}</em>
99+
</span>
100+
</span>
101+
</th>
102+
</tr>
103+
</thead>
104+
<tbody>
105+
{% for entryType in section.entryTypes %}
106+
{% set entryTypeCount = craft.entries.section(section.handle).type(entryType.handle).count %}
107+
{% set limitValue = settings.sections[section.handle][entryType.handle].limit|default('') %}
108+
<tr class="entryTypeRulesLimit" data-count="{{ entryTypeCount }}">
109+
<td>
110+
<strong>{{ entryType.name }}</strong> <i>{{ entryType.handle }}</i><br/>
111+
<span class="entryTypeRulesLimit__count inline-block">
112+
{{ "Entries"|t('entry-type-rules') }}: {{ entryTypeCount }}
113+
</span>
114+
<span class="entryTypeRulesLimit__warning inline-block ml-2 warning hidden" style="margin-top: -3px; margin-left: 5px;">
115+
<span class="icon" aria-hidden="true"></span>
116+
<span class="visually-hidden">{{ "Warning"|t('entry-type-rules') }}: </span>
117+
</span>
118+
</td>
119+
<td>
120+
<div class="entryTypeRulesLimit__input">
121+
{{ forms.textField({
122+
id: (entryType.handle ~ '_limit'),
123+
name: ('sections[' ~ section.handle ~ ']['~ entryType.handle ~ '][limit]'),
124+
type: 'number',
125+
size: 5,
126+
min: 0,
127+
value: limitValue,
128+
placeholder: '0',
129+
unit: "Entries"|t('entry-type-rules'),
130+
}) }}
131+
</div>
132+
</td>
133+
<td>
134+
{{ forms.checkboxSelectField({
135+
id: (entryType.handle ~ '_userGroups'),
136+
name: ('sections[' ~ section.handle ~ ']['~ entryType.handle ~ '][userGroups]'),
137+
options: groupOptions,
138+
showAllOption: true,
139+
allValue: '',
140+
values: settings.sections[section.handle][entryType.handle].userGroups|default('')
141+
}) }}
142+
</td>
143+
</tr>
144+
{% endfor %}
145+
</tbody>
146+
</table>
147+
</section>
148+
149+
{% endfor %}
150+
{% endif %}
141151

142152
{% endblock %}
143153

src/translations/en/entry-type-rules.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Entry Type Rules plugin for Craft CMS 3.x
45
*
@@ -38,4 +39,6 @@
3839
'Limit which user groups can add new entries for the entry type.' => 'Limit which user groups can add new entries for the entry type.',
3940
'Admin users will always be able to add new entries.' => 'Admin users will always be able to add new entries.',
4041
'Entries' => 'Entries',
42+
'configureSections' => 'You need to <a href="{url}">configure some Sections</a> first.',
43+
'configureEntries' => 'You need to create some <a href="{url}">entries</a> first.</p>',
4144
];

0 commit comments

Comments
 (0)