1

If a user has permission to publish on multiple sites, he by default publishes to all of them. If he wants to exclude some sites, he needs to go in each one and turn off the post for that site. This is ok if you have several sites, but on +100 sites it is a very time consuming task.

It occured to me that we could use one user account for publishing on one site and another for publishing on multiple sites, but again, if you don't want to publish on all 100+ sites, you still have to invest a lot of time to disable the post for unwanted sites.

I found this field type plugin, but i am not sure if it can accomplish what I want. https://github.com/eastslopestudio/craft3-sites-field

I think something like a list with checkboxes would be ideal for this (like the one in user permissions for Sites) with the current Site being automaticaly initially checked. Or a multi select field maybe.

Is something like that doable? If not with core Craft then maybe with a plugin?

Thanks in advance for any advice!

1

It sounds like this is something that could be done using a module. You could use the sites field type to select the sites you want to enable the entry for, and then listen to the beforeSave event to enable the selected sites (and disable all others).

You would listen for, and act on, this event in your module's init method.

The beforeSave event gets called for every site the entry gets saved for, so it could be something like (untested):

Event::on(Entry::class, Entry::EVENT_BEFORE_SAVE, function (ModelEvent $event) {
    // Get the entry from the event
    $entry = $event->sender;

    if (
        $entry->type->id == 1 // <-- Section type ID for entry
        && !in_array(
            $entry->siteId,
            $entry->getFieldValue('visibleOnSites')
        )
    ) {
        $entry->enabledForSite = false;
    }
}

This assumes that entries are enabled for every site by default, and that propagation for this section is active.

1

We've forked the plug-in and allowed for entry propagation trough different sites as a feature, if you enable propagation the plug-in will automatically enable the post for the selected sites.

https://github.com/wirelab/craft3-sites-propegation-field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.