In the CP, is it possible to disable Category X for site A, and not for Site B? And if so, how?
-
Via custom php code/plugin or via cp request? – Robin Schambach Nov 21 '17 at 09:08
-
In the CP. Edited question. – Paul Nov 21 '17 at 09:11
1 Answers
I guess it is either a bug or the developers don't want us to do it via cp request. In my plugin (phpCode) I can activate and deactivate categories per site easily but the cp template is missing the required input. When you compare the route of a category and an entry you'll notice it easily
Take a look at entries/_edit.html
<ul id="sites" class="pane">
{% set parentIdParam = craft.app.request.getParam('parentId.0') ?: craft.app.request.getParam('parentId') %}
{% for siteId in siteIds %}
{% set site = craft.app.sites.getSiteById(siteId) %}
<li{% if siteId == entry.siteId %} class="sel"{% endif %}>
{%- if siteId == entry.siteId -%}
{{ site.name|t('site') }}
{{ forms.lightswitch({
name: 'enabledForSite',
on: entry.enabledForSite,
small: true,
disabled: isVersion
}) }}
{%- else -%}
{% set siteEntryUrl = url(
'entries/'~sectionHandle~'/'~craft.app.request.getSegment(3)~'/'~site.handle,
(parentIdParam ? { parentId: parentIdParam })
) -%}
<a href="{{ siteEntryUrl }}">{{ site.name|t('site') }}</a>
<div class="status {{ siteId in enabledSiteIds ? 'enabled' : 'disabled' }}"></div>
{%- endif -%}
</li>
{% endfor %}
</ul>
and the categories/_edit.html
<ul id="sites" class="pane">
{% set parentIdParam = craft.app.request.getParam('parentId.0') ?: craft.app.request.getParam('parentId') %}
{% for siteId in siteIds %}
{% set site = craft.app.sites.getSiteById(siteId) %}
<li{% if siteId == category.siteId %} class="sel"{% endif %}>
{%- if siteId == category.siteId -%}
{{ site.name|t('site') }}
{%- else -%}
{% set siteCategoryUrl = url(
'categories/'~groupHandle~'/'~craft.app.request.getSegment(3)~'/'~site.handle,
(parentIdParam ? { parentId: parentIdParam })
) -%}
<a href="{{ siteCategoryUrl }}">{{ site.name|t('site') }}</a>
{%- endif -%}
</li>
{% endfor %}
</ul>
It's missing the
{{ forms.lightswitch({
name: 'enabledForSite',
on: entry.enabledForSite,
small: true,
disabled: isVersion
}) }}
even though when I include the input to the template it does not work since it's not populated correctly. The _populateCategoryModel method does not recognize the field.
To compare it: EntriesController:
private function _populateEntryModel(Entry $entry)
{
// Set the entry attributes, defaulting to the existing values for whatever is missing from the post data
$entry->typeId = Craft::$app->getRequest()->getBodyParam('typeId', $entry->typeId);
$entry->slug = Craft::$app->getRequest()->getBodyParam('slug', $entry->slug);
$entry->postDate = (($postDate = Craft::$app->getRequest()->getBodyParam('postDate')) !== false ? (DateTimeHelper::toDateTime($postDate) ?: null) : $entry->postDate);
$entry->expiryDate = (($expiryDate = Craft::$app->getRequest()->getBodyParam('expiryDate')) !== false ? (DateTimeHelper::toDateTime($expiryDate) ?: null) : null);
$entry->enabled = (bool)Craft::$app->getRequest()->getBodyParam('enabled', $entry->enabled);
$entry->enabledForSite = (bool)Craft::$app->getRequest()->getBodyParam('enabledForSite', $entry->enabledForSite);
$entry->title = Craft::$app->getRequest()->getBodyParam('title', $entry->title);
has the $entry->enabledForSite but the CategoryController
private function _populateCategoryModel(Category $category)
{
// Set the category attributes, defaulting to the existing values for whatever is missing from the post data
$category->slug = Craft::$app->getRequest()->getBodyParam('slug', $category->slug);
$category->enabled = (bool)Craft::$app->getRequest()->getBodyParam('enabled', $category->enabled);
$category->title = Craft::$app->getRequest()->getBodyParam('title', $category->title);
does not have it
If you want you could create a plugin to fix this issue, it's actually not that complicated since you can change everything in craft now, so you could overwrite the function. But It would be easier to create a ticket with a feature request or something. Maybe Brad could make it clearer
To Resume
If you want to enable categories per site, you have to include the field to the template and to the controller in _populateCategoryModel then it works
- 19,713
- 1
- 19
- 44