Content Repository

Neos 9

This page is for Neos 9.0 with the new Event Sourced Content Repository.

#The API

none
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);

// $contentRepository is of type Neos\ContentRepository\Core\ContentRepository
// and is the central API:

// access the node type manager
$contentRepository->getNodeTypeManager()->...

// access the content graph (the main read model)
$contentRepository->getContentGraph(WorkspaceName::forLive())->...

// modify the content repository
$contentRepository->handle(SetNodeProperties::create(...));

The ContentRepository is the main public API you'll interact with, which you'll retrieve by calling ContentRepositoryRegistry::get($contentRepositoryId). It is responsible for:

  • sending commands to the system to mutate state via ContentRepository::handle($command)
  • accessing projection state (to read the current model) via
    • ContentRepository::getContentGraph($workspaceName)
    • ContentRepository::findWorkspace()
    • ContentRepository::findWorkspaceByName($workspaceName)
    • or custom projections via ContentRepository::projectionState(CustomProjectionState::class) 
  • accessing configuration:
    • accessing the NodeTypeManager via ContentRepository::getNodeTypeManager()
    • accessing Dimension Configuration via ContentRepository::getVariationGraph() and ContentRepository::getContentDimensionSource()

#Accessing the Content Repository Id

If you received a ContentRepository instance from somewhere from the framework, you can assume this is the correct instance.

If you write PHP controllers, you can retrieve the ContentRepositoryId from the SiteDetectionResult via the following snippet:

YourController.php
<?php

class YourController extends ActionController
{
    public function indexAction() 
	{
        $contentRepositoryId = SiteDetectionResult::fromRequest($this->request->getHttpRequest())->contentRepositoryId;

        // for reference, this is how you fetch the ContentRepository then.
        $contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
   }
}

#Setting up database schema

Setting up the necessary database tables and contents via a dedicated service:

php
$contentRepositoryMaintainer = $this->contentRepositoryRegistry->buildService(
	$contentRepositoryId,
	new ContentRepositoryMaintainerFactory()
);

$contentRepositoryMaintainer->setUp();