Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector::getPublishedLocales PHP Method

getPublishedLocales() public method

Return the published locales for the given document.
public getPublishedLocales ( Sulu\Component\Content\Document\Behavior\ShadowLocaleBehavior $document ) : array
$document Sulu\Component\Content\Document\Behavior\ShadowLocaleBehavior
return array
    public function getPublishedLocales(ShadowLocaleBehavior $document)
    {
        $node = $this->getNode($document);
        $locales = $this->getLocales($document);
        $publishedLocales = [];
        foreach ($locales as $locale) {
            $publishedPropertyName = $this->encoder->localizedSystemName(WorkflowStageSubscriber::PUBLISHED_FIELD, $locale);
            if ($node->getPropertyValueWithDefault($publishedPropertyName, false)) {
                $publishedLocales[] = $locale;
            }
        }
        return $publishedLocales;
    }

Usage Example

Example #1
0
 /**
  * Invalidates the assigned structure and all urls in all locales of the document when a document gets removed.
  * This method is executed before the actual removing of the document because the document must still
  * exist to gather the urls of the document.
  *
  * @param RemoveEvent $event
  */
 public function invalidateDocumentBeforeRemoving(RemoveEvent $event)
 {
     $document = $event->getDocument();
     if ($document instanceof StructureBehavior) {
         $this->invalidateDocumentStructure($document);
     }
     if ($document instanceof ResourceSegmentBehavior) {
         foreach ($this->documentInspector->getPublishedLocales($document) as $locale) {
             $this->invalidateDocumentUrls($document, $locale);
         }
     }
 }