Skip to content

Commit

Permalink
Normalize getLocales for categories, entries, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Kelty committed Nov 9, 2017
1 parent 46f6ab8 commit 27fc97d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions services/LocaleSyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ public function syncElementContent(Event $event, $elementSettings)
$this->_elementBeforeSave = craft()->elements->getElementById($this->_element->id, $this->_element->elementType, $this->_element->locale);
$locales = $this->_element->getLocales();

// Matrix elements return a non-associative array from getLocales(). Normalize it.
// Normalize getLocales() from different elementTypes
if ($this->_element instanceof MatrixBlockModel) {
$locales = array_flip($locales);
} elseif ($this->_element instanceof EntryModel) {
$locales = array_keys($locales);
}

$defaultTargets = array_key_exists($this->_element->locale, $pluginSettings->localeDefaults) ? $pluginSettings->localeDefaults[$this->_element->locale]['targets'] : [];
Expand All @@ -75,7 +77,7 @@ public function syncElementContent(Event $event, $elementSettings)
$targets = $defaultTargets;
}

foreach ($locales as $localeId => $localeInfo)
foreach ($locales as $localeId)
{
$localizedElement = craft()->elements->getElementById($this->_element->id, $this->_element->elementType, $localeId);
$matchingTarget = $targets === '*' || in_array($localeId, $targets);
Expand Down

0 comments on commit 27fc97d

Please sign in to comment.