Propagate an entry to a new site via API #13620
-
We have a platform with multilingual sites. As our content is growing bigger, it becomes time-consuming to manually propagate each entry to all sites using the UI (Add a site button). Thus we are looking to build a plugin to surface a button to propagate an entry to all of its supported sites at once. We can use However, we cannot find a public method in Entry element to achieve that. Is there a method that we can use to propagate the entry to a single site? Like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Here’s how you can tell the entry to propagate to a new site(s): use Craft;
use craft\helpers\ElementHelper;
// Get the current supported sites/statuses
$siteStatuses = ElementHelper::siteStatusesForElement($entry);
// Add the new ones
// (set to false if you want the entry to be disabled for the new site)
$siteStatuses[$newSiteId] = true;
// ...
// Save the entry with the new list of supported sites/statuses
$entry->setEnabledForSite($siteStatuses);
Craft::$app->elements->saveElement($entry); |
Beta Was this translation helpful? Give feedback.
-
Absolutely work! Thanks a lot @brandonkelly 🙏 |
Beta Was this translation helpful? Give feedback.
Here’s how you can tell the entry to propagate to a new site(s):