Creating Documents

The Sulu Document Manager uses interfaces to determine how a document is handled. These interfaces are known as behaviors. Behaviors act upon documents.


It is equally possible to implement what is now the conventional mapping pattern using XML, YAML, annotation, etc. But for now only behavioral interfaces are supported.

The Document


namespace Acme\Bundle\FooBundle\Document;

use Sulu\Component\DocumentManager\Behavior\Mapping\NodeNameBehavior;
use Sulu\Component\DocumentManager\Behavior\Mapping\PathBehavior;
use Sulu\Component\DocumentManager\Behavior\Mapping\UuidBehavior;

class SomeDocument implements
    private $nodeName;
    private $path;
    private $uuid;
    private $targetDocument;

    public function getNodeName()
        return $this->nodeName;

    public function getPath()
        return $this->path;

    public function getUuid()
        return $this->uuid;

The above document will have the nodes path, UUID and node name populated. The properties are mandatory and the behaviors will expect them to be there, if they are not then an exception will be thrown explaining which properties need to be added.


The behaviors will often use Reflection to set the value of an objects properties, bypassing any protection that property may have.


Because the Document Manager uses interfaces and does not depend on metadata mapping you can put your document anywhere you want without changing any configuration.

Defining the alias and type

In order for the document manager to recognize existing managed documents and persist new ones, you must add some mapping to your configuration.

The following configuration should be added to the config/packages/sulu_document_manager.yaml file:

        # ...
            phpcr_type: acme:somedocument
            class: Acme\Bundle\FooBundle\Document\SomeDocument

Above we define three things:

  1. The alias of the document as my_new_document. This alias can be used instead of the long class name when managing the document.
  2. A PHPCR type which will be used to map the document to the class name.
  3. The class which should be managed.