-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to disable a single site #3005
Comments
This would be great to see imo |
If a site is disabled, I think it would also become hidden throughout the Control Panel, which probably isn’t what you’d want? If you don’t want people to access a site on the front end, then just disable its “This site has its own base URL” setting. Then the only way you could access its content on the front-end is if the CRAFT_SITE constant is explicitly telling Craft to load content from that site. |
@brandonkelly Why would it need to be hidden throughout the Control Panel? Removing the base URL for a site would make it really hard to work on, test, etc. |
I guess on second thought it could be shown only in the Control Panel if disabled, with a red status indicator. |
@khalwat Couldn’t you just look at the |
I do that already, yes @brandonkelly |
So what exactly would the ability to disable a site do, that disabling URLs doesn’t already do? |
@brandonkelly The goal is able to have sites that can be worked on before they are ready to go live. So if you are working on a new Spanish version of your site, you need to be able to look at the pages, share them (internally), etc. |
I have a specific use case that relates to this discussion. We are building websites for the franchise network of a large insurance company in Belgium. The specific thing about this solution is that all sites will share the same design and codebase and would be deployed multiple times for the individual sites and their own license while keeping the codebase in 1 repository. The additions to version 3.1 are a true godsend, it allows us to be very efficient ! The only thing we are struggling with at this moment is the site configurations, as this is Belgium (everything is difficult here) we need to deal with
The idea is that we define a project.yaml with 3 sites / language and then define in config files what sites (languages) are enabled or disabled and what the default would be (just like we do for the hostnames, mailaddresses and so forth), since we want to stick to one codebase (and thus one project.yaml file). |
@timbertens This wouldn’t solve that completely, since your builds will have different primary sites. And I think the idea here is that Craft will still generally be storing content across all sites per section rules, etc., in anticipation of the sites becoming enabled down the road. It would be annoying to have to wait around for Craft to store content in sites it’s never going to need. |
@brandonkelly just an update on this from my side: in this solution we have to live with the fact that it causes a small delay for storing content in languages that will never be needed. It is faster it that doesn't happen of course, but the performance is still okay (and more important, the codebase and settings are kept the same for all installations) While looking for a solution, we've came up with this addition in the web/index.php file
As you can see the OVERRIDED_DEFAULT_SITE is set in the .env site for the particular installation. I believe a small addition could solve the other use cases too (4 and 5 from the above comment). If there would be a PHP CONSTANT named eg 'PRIMARY_CRAFT_SITE' that sets the primary Craft site in case Craft cannot determine what site to show (so that logic remains) |
@brandonkelly I don't know how the project management of Craft CMS is going or being handled, but are these "3.2" features still in active development and will they be added? |
@michtio Clearly they didn’t make the cut for 3.2 :) Still want to get to things on the 3.2 and 3.3 milestones, but we will need to reevaluate when exactly they make it in. |
@brandonkelly thanks for the reply, hopefully sooner than later! :D Maybe add the things that didn't make it in for Craft 3.5? ;p |
Any chance this is coming sooner than later? A company I started working for will be adding several countries throughout the year, each country having at least a native language plus English as sites. It would be really nice to have one setting to keep that site off while the content editors can go in and do their thing... |
The timing of this couldn't be more amazing. Thank you so much!!! |
@brandonkelly Would it be possible to adjust the site status Similar to what @timbertens mentioned above, we have a project that will use the same codebase for two separate sites, each having English/French languages as sites in Craft. Each site needs to have its French language disabled until translation is complete, but these won't occur at the same time. This status saves to the project config – affecting both sites, so it makes it difficult to manage the proper settings for each. |
@jsunsawyer We need to come up with a good UI for setting non-textual values with environment variables. In the meantime, you could do this from a module: use craft\helpers\App;
use craft\models\Site;
use yii\base\Event;
Event::on(Site::class, Site::EVENT_INIT, function(Event $event) {
/* @var Site $site */
$site = $event->sender;
switch ($site->handle) {
case 'siteA':
$site->enabled = (bool)App::env('SITE_A_ENABLED');
break;
case 'siteB':
$site->enabled = (bool)App::env('SITE_B_ENABLED');
break;
}
}); |
@brandonkelly Thanks! I'll give this a shot. |
@brandonkelly I couldn't get this to work. Any chance you could test this out on your end and verify that what you posted should be working for me? |
@jsunsawyer @brandonkelly I only got it working when I place the code snippet in the index.php in the public folder where Craft get's initiated! |
@kobeaerts Thanks so much! I got it working as well by placing it there. Small note for anyone else, the Event must be placed before |
If anyone here has any thoughts on #7996 I’d appreciate the input! |
Custom 503/offline template would be very useful.
Really like this approach. Think I would prefer the 503 option or maybe let the user choose the status when disabling the specific site for maximum flexibility. |
The concern I have with 503 is that it would provide some insight into the fact that there is an actual site there – where currently there’s none. If we go with the latter option (404s for all non-exact-matches) then we are continuing to ignore disabled sites, so the client has no way of knowing via the 404 response whether they’ve hit a disabled site, or just not one of the configured sites. |
Both options can be valid for a given situation. Giving the developer the option to choose from the 404 or 503 and handle the template accordingly seems like the most flexible option. |
I don't have a strong opinion as to which HTTP response code would be the better option, but I think it would be a good idea to be clearer about which behaviour the "Enabled on the front-end?" setting is supposed to mimic or resemble – is it supposed to be a per-site |
Nice @brandonkelly!! Another question on this, is it also possible to set an option to not render the Site in the Control Panel? Currently this feature you created allows us to disable the site via an See it as a white label app with all its logic that uses Craft CMS. |
@bzin You can keep non-admins from seeing them by not assigning the sites’ permissions, but there’s no way to hide them for admins. Wouldn’t make any sense from Craft’s perspective – at that point there would be no way in the UI to get the site back. |
Craft 4.0.0-RC1 is out with the ability to set site statuses with environment variables. |
Description
It would be great if we could disable a single site in the CP. There are many reasons you may want to do this but the main one is that when you are first translating a site, you probably don't want that in-progress site to be visible on the front-end.
Having this be core functionality would allow plugin authors to check if a site is enabled. For example, SEOmatic may want check if a site is enabled before adding metadata about that site or adding it to the sitemap.
Additional info
The text was updated successfully, but these errors were encountered: