Ejemplo n.º 1
0
 /**
  * Writes the history status of the node to the document.
  *
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof RouteBehavior) {
         return;
     }
     $document->setHistory($event->getNode()->getPropertyValue(self::NODE_HISTORY_FIELD));
 }
Ejemplo n.º 2
0
 /**
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof PathBehavior) {
         return;
     }
     $event->getAccessor()->set('path', $this->documentInspector->getPath($document));
 }
 /**
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof ChildrenBehavior) {
         return;
     }
     $accessor = $event->getAccessor();
     $accessor->set('children', $this->proxyFactory->createChildrenCollection($document, $event->getOptions()));
 }
 /**
  * It should not register documents on the HYDRATE event when there is already a document.
  */
 public function testHandleRegisterHydrateAlreadyExisting()
 {
     $this->hydrateEvent->getDocument()->willReturn($this->document);
     $this->hydrateEvent->getNode()->willReturn($this->node->reveal());
     $this->hydrateEvent->getLocale()->willReturn('fr');
     $this->registry->hasDocument($this->document)->willReturn(true);
     $this->registry->registerDocument($this->document, $this->node->reveal(), 'fr')->shouldNotBeCalled();
     $this->registry->updateLocale($this->document, 'fr')->shouldBeCalled();
     $this->subscriber->handleHydrate($this->hydrateEvent->reveal());
 }
 /**
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof TimestampBehavior) {
         return;
     }
     $node = $event->getNode();
     $locale = $event->getLocale();
     $accessor = $event->getAccessor();
     $accessor->set(self::CREATED, $node->getPropertyValueWithDefault($v = $this->encoder->localizedSystemName(self::CREATED, $locale), null));
     $accessor->set(self::CHANGED, $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::CHANGED, $locale), null));
 }
Ejemplo n.º 6
0
 /**
  * Adds the security information to the hydrated object.
  *
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     $node = $event->getNode();
     if (!$this->supports($document)) {
         return;
     }
     $permissions = [];
     foreach ($node->getProperties('sec:*') as $property) {
         /** @var PropertyInterface $property */
         $roleId = substr($property->getName(), 9);
         // remove the "sec:role-" prefix
         $permissions[$roleId] = $property->getValue();
     }
     $document->setPermissions($permissions);
 }
Ejemplo n.º 7
0
 /**
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     // we currently only support fallback on StructureBehavior implementors
     // because we use the template key to determine localization status
     if (!$document instanceof StructureBehavior) {
         return;
     }
     $locale = $event->getLocale();
     if (!$locale || false === $event->getOption('load_ghost_content', true)) {
         return;
     }
     // change locale of document of ghost content should be loaded
     $newLocale = $this->getAvailableLocalization($document, $locale);
     $event->setLocale($newLocale);
     $document->setLocale($newLocale);
 }
 /**
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     // we currently only support fallback on StructureBehavior implementors
     // because we use the template key to determine localization status
     if (!$document instanceof StructureBehavior) {
         return;
     }
     $locale = $event->getLocale();
     if (!$locale) {
         return;
     }
     $newLocale = $this->getAvailableLocalization($document, $locale);
     $event->setLocale($newLocale);
     if ($newLocale === $locale) {
         return;
     }
     if ($event->getOption('load_ghost_content', true) === true) {
         $this->documentRegistry->updateLocale($document, $newLocale, $locale);
         return;
     }
     $this->documentRegistry->updateLocale($document, $locale, $locale);
 }
 /**
  * When the hydrate request has finished, mark the document has hydrated.
  * This should be the last event listener called.
  *
  * @param HydrateEvent $event
  */
 public function handleEndHydrate(HydrateEvent $event)
 {
     $this->documentRegistry->markDocumentAsHydrated($event->getDocument());
 }
Ejemplo n.º 10
0
 /**
  * Determines if the given document is supported by this subscriber.
  *
  * @param HydrateEvent|PublishEvent|PersistEvent $event
  *
  * @return bool
  */
 private function supports($event)
 {
     return $event->getLocale() && $event->getDocument() instanceof WorkflowStageBehavior;
 }
Ejemplo n.º 11
0
 /**
  * Set routes to custom-url.
  *
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof CustomUrlBehavior) {
         return;
     }
     $webspaceKey = $this->inspector->getWebspace($document);
     $document->setRoutes($this->findReferrer($document, $webspaceKey));
 }
 /**
  * @param HydrateEvent $event
  */
 public function handleHydrate(HydrateEvent $event)
 {
     $document = $event->getDocument();
     if (!$document instanceof ParentBehavior) {
         return;
     }
     $node = $event->getNode();
     if ($node->getDepth() == 0) {
         throw new \RuntimeException(sprintf('Cannot apply parent behavior to root node "%s" with type "%s" for document of class "%s"', $node->getPath(), $node->getPrimaryNodeType()->getName(), get_class($document)));
     }
     $this->mapParent($document, $node);
 }