Yes, of course. For tailor this would help a lot. This would be column is_enabled=false, right?
For custom models not, as there is no standard column for that, as far as I know. So here adhering to $propagatable[] already upon record creation would be the easiest solution i guess (so one can have a field like is_published with default false, don’t have it in $propagatable and multisite propagation would omit it from the insert)
Actually yesterday I asked chatgpt to help me to make my custom model propagation work like that. With a customMultisite Trait:
<?php
namespace Kinderradfinder\BicyclesCatalogue\Traits;
use site;
trait CustomMultisite
{
/**
* Find an existing model for the specified site or create a new one,
* setting only the propagatable attributes for new models.
*
* @param mixed $siteId The site ID for which the model should be found or created.
* @return Model The model instance for the specified site.
*/
protected function findOtherSiteModel($siteId = null)
{
if ($siteId === null) {
$siteId = $this->getSiteIdFromContext();
}
if ($this->isModelUsingSameSite($siteId)) {
return $this;
}
$otherModel = $this->findForSite($siteId);
// If a model for the other site doesn't exist, replicate the current model
// with only the necessary attributes.
if (!$otherModel) {
$replicated = $this->replicateWithRelations();
// Define the attributes that should always be maintained
$alwaysKeep = ['created_at', 'deleted_at', 'updated_at', 'site_id', 'site_root_id', 'sort_order'];
// Get all attribute keys from the model
$attributes = array_keys($this->getAttributes());
// Determine which attributes should be unset
$attributesToUnset = array_filter($attributes, function ($attributeKey) use ($alwaysKeep) {
return !in_array($attributeKey, $this->propagatable) &&
!in_array($attributeKey, $alwaysKeep) &&
substr($attributeKey, -3) !== '_id';
});
// Unset non-propagatable attributes, except for those ending with '_id'
foreach ($attributesToUnset as $attributeKey) {
unset($replicated->{$attributeKey});
}
$otherModel = $replicated;
$otherModel->{$this->getSiteIdColumn()} = $siteId;
$otherModel->site_root_id = $this->site_root_id ?: $this->id;
}
return $otherModel;
}
/**
* Get the current site ID from the application context.
*
* @return mixed The current site ID.
*/
protected function getSiteIdFromContext()
{
// Implement logic to retrieve the current site ID from the application context.
// This is a placeholder and needs to be adapted based on your application's context management.
return Site::getSiteIdFromContext();
}
}
?>
…which I then use alongside the standard multisite trait in my model:
use October\Rain\Database\Traits\Multisite as OriginalMultisite;
use Kinderradfinder\BicyclesCatalogue\Traits\CustomMultisite;
use OriginalMultisite, CustomMultisite {
CustomMultisite::findOtherSiteModel insteadof OriginalMultisite; // Ensure CustomMultisite's version is used.
}
…probably not nice, but it seems to work for my model. But Tailor is_enabled is another story, where not me nor chatgpt had an idea how to cleanly interfere.
So, yes: If you made replicated models unpublished by default, that would definitely help a lot!