-1

I have two pages in my content tree n sulu 1.0.13. On page "A" I set a reference to page "B" with a field of the content type "single internal link".

When I am on page "B" I want to get the referring page "A". I have tried following code in my controller:

$dm  = $this->get('sulu_document_manager.document_manager');
$doc = $dm->find('992758cf-1da4-4e45-9ee4-ca9c4ec3998e'); // UUID of page "B"
$di  = $this->get('sulu_document_manager.document_inspector');
$node = $di->getNode($doc);

$refs = $di->getReferrers($doc); // $refs is an empty collection
$refs = $node->getReferences(); // $refs is an empty collection
$refs = $node->getWeakReferences(); // $refs is an empty collection

$refs is always an empty collection.

What is the right way to get the referring page?

Update: I now use version 1.1.0 RC2

huzi
  • 131
  • 1
  • 8
  • Your question is not at all clear. Please describe your issue more clearly and show an attempt to solve the problem on your own. – Greg Nov 20 '15 at 01:08

1 Answers1

3

Sadly the SingleInternalLink content type is currently just saving the UUID as a string, and not as a proper reference in PHPCR. This is also described in this GitHub Issue. I will reevaluate this issue, and see if we can fix that in the near future.

As a workaround you could use the InternalLinks content type, which already saves its values as references, although it is possible to add more than one link.

Daniel Rotter
  • 1,998
  • 2
  • 16
  • 33
  • I have tried InternalLinks and now it works, But I get two elements if I call `$refs = $di->getReferrers($doc);`. One of type `Sulu\Bundle\ContentBundle\Document\RouteDocument` and the other one of type `Sulu\Bundle\ContentBundle\Document\PageDocument`. – huzi Nov 22 '15 at 16:39
  • I have the issue with version 1.1.0 RC2 – huzi Nov 22 '15 at 17:21
  • Yeah, the issue isn't fixed yet in any version... And that's right, I didn't think about that... You probably have to check if the document is from type `PageDocument`. Routes have its own tree, and are also referencing pages, this is why you get two referrers. – Daniel Rotter Nov 23 '15 at 15:13