Skip to content

Commit

Permalink
Ensure entries created through their fields respect their default status
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Feb 21, 2019
1 parent 5a9dec4 commit b83a44f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/fields/Entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,27 @@ private function _createElement($dataValue, $sources)
$siteId = Hash::get($this->feed, 'siteId');
$propagate = $siteId ? false : true;

$section = Craft::$app->sections->getSectionById($element->sectionId);

if ($siteId) {
$element->siteId = $siteId;

// Set the default site status based on the section's settings
foreach ($section->getSiteSettings() as $siteSettings) {
if ($siteSettings->siteId == $siteId) {
$element->enabledForSite = $siteSettings->enabledByDefault;
break;
}
}
} else {
// Set the default entry status based on the section's settings
foreach ($section->getSiteSettings() as $siteSettings) {
if (!$siteSettings->enabledByDefault) {
$element->enabled = false;
}

break;
}
}

if (!Craft::$app->getElements()->saveElement($element, true, $propagate)) {
Expand Down

0 comments on commit b83a44f

Please sign in to comment.