Cms: Remove restriction that section names have to be unique

Created on 26 Jan 2018  Â·  10Comments  Â·  Source: craftcms/cms

With multi sites it’s quite common that you would want to have sections with the same name. In the CP’s sources list UI this is no longer a problem, since you can nicely sort sections into section groups.

enhancement

All 10 comments

I’m open to it, but it would get confusing on Settings → Sections, so we would need to come up with a better way to organize sections (maybe a site menu there).

For now, one thing you can do is customize their names using static translations. So for example if you have two sections named “My Section (Site A)” and “My Section (Site B)”, you could create a translations/<lang>/site.php file, and add this:

<?php

return [
    'My Section (Site A)' => 'My Section',
    'My Section (Site B)' => 'My Section',
];

Oh nice, didn’t think about using translations as a workaround in this case. Thanks! I don’t really follow how you mean it would be confusing in Settings > Sections as there’s the handle column right next to the name.

That’s true, the handle would help clarify.

@brandonkelly the workaround with static translations causes issues with user permissions settings, the second section “My Section (Site B)” doesn’t show in the list.

Ah, because user permissions are indexed by permission group name. Maybe just add a space to the end of one of the translations to make them unique?

Damn, and I was hoping you wouldn't think of this workaround and push this FR up a bit in your list. It took me quite some time to figure out who the client complained that they weren't able to assign certain permission.

Hah, actually it had the opposite effect. I hadn’t thought of the user permissions list originally, but having two sections in there with the exact same name would be pretty confusing.

Adding the type of the section (channel / single) or handle after the name could fix that. Or if it really needs to be pretty an info balloon with the handle/type. And if people really want to shoot themselves in the foot.. well it's nice if you let them :) I actually have the usecase quite often on multiple sites where i need an overview page and a channel of detail pages (f.e. news)

That said, after using the suggestion to use the translations there are multiple places where it is unclear which section you choose. For instance, also in the Entry field type. And it would be nice if a handle would be available there as well.

In general I think that would help craft in name confusion, because an already existing place where the same confusion takes place is when adding fields to a fieldlayout, if they happen to have the same name.

Played around with modifying how permissions are defined, but decided against it since this is the only really point in doing it, and I don’t think that is adding enough value to warrant a breaking change. And as @jurriaanr pointed out, even if both sections show up, there is still going to be confusion throughout the Settings area about which section you’re dealing with.

So then I started removing the Craft::t() calls and |t filters when outputting section names in the Settings area, with the goal of only translating section names on pages related to content administration. That’s not going to work either, unfortunately, because one of the places section names get translated is craft\elements\Entry::defineSources(), which defines the available entry sources, and that is used in both system administration (Entries field settings) and content administration (sidebar of entry indexes). I wasn’t feeling comfortable with that change in the first place, and am definitely against it if it’s going to require adding any amount of code complexity.

That did get me thinking, though, that maybe the best approach here is that you could only translate the section names for non-admins, or users in a specific group, etc. Here’s how you could pull that off from your translation file:

<?php

$translations = [
    // ...
];

if (!Craft::$app->getUser()->getIsAdmin()) {
    $translations['My Section (Site A)'] = 'My Section';
    $translations['My Section (Site B)'] = 'My Section';
}

return $translations;
Was this page helpful?
0 / 5 - 0 ratings

Related issues

lukebailey picture lukebailey  Â·  3Comments

mattstein picture mattstein  Â·  3Comments

michaelhue picture michaelhue  Â·  3Comments

RitterKnightCreative picture RitterKnightCreative  Â·  3Comments

leigeber picture leigeber  Â·  3Comments