Return locales which are not shadows.
public getConcreteLocales ( Sulu\Component\Content\Document\Behavior\ShadowLocaleBehavior $document ) : array | ||
$document | Sulu\Component\Content\Document\Behavior\ShadowLocaleBehavior | |
Результат | array |
/** * Adds the concrete languages available and the type (ghost or shadow) of the document to the serialization. * * @param ObjectEvent $event */ public function onPostSerialize(ObjectEvent $event) { $document = $event->getObject(); if (!$document instanceof LocaleBehavior || !$this->documentRegistry->hasDocument($document)) { return; } $visitor = $event->getVisitor(); $visitor->addData('concreteLanguages', $this->documentInspector->getConcreteLocales($document)); $localizationState = $this->documentInspector->getLocalizationState($document); if ($localizationState === LocalizationState::GHOST) { $visitor->addData('type', ['name' => 'ghost', 'value' => $document->getLocale()]); } if ($localizationState === LocalizationState::SHADOW) { $visitor->addData('type', ['name' => 'shadow', 'value' => $document->getLocale()]); } }
private function validateShadow(ShadowLocaleBehavior $document) { if ($document->getLocale() === $document->getShadowLocale()) { throw new \RuntimeException(sprintf('Document cannot be a shadow of itself for locale "%s"', $document->getLocale())); } $locales = $this->inspector->getConcreteLocales($document); if (!in_array($document->getShadowLocale(), $locales)) { $this->inspector->getNode($document)->revert(); throw new \RuntimeException(sprintf('Attempting to create shadow for "%s" on a non-concrete locale "%s" for document at "%s". Concrete languages are "%s"', $document->getLocale(), $document->getShadowLocale(), $this->inspector->getPath($document), implode('", "', $locales))); } }
public function getConcreteLanguages() { return $this->inspector->getConcreteLocales($this->getDocument()); }