Table of Contents

Entity view repository context

Entity view repositories operate within an execution context. This context serves to:

  • Define the condition expression for filtering via quick search.
  • Specify additional data to retrieve (e.g. display value of lookups).

The execution context varies depending on the calling UI view.

When accessing data through entity view APIs, the execution context is automatically set using the neos-ui-view-name HTTP header, which specifies the name of the calling UI view.

However, when calling a server-side method API, this execution context is not automatically defined and must be set manually if needed.

To set it manually, inject the IEntityViewRepositoryContext<TEntityView> interface, where TEntityView is the type of your entity view interface, and call the SetUIViewName(string uiViewName) method with the name of the UI view you want to use as context.

Example

In the following example, the server method will apply processing to the items that the user has filtered on the UI.

The server method is called when clicking on an UI view action button. The OData filter currently applied to the UI is passed to the server method.

The user could filter via the quick search or on a displayed value of a lookup property. For the filter to work, the context of the entity view repository must be defined.

public class ValidateFilteredInvoices : IValidateFilteredInvoices
{
    private readonly IInvoiceListViewRepository _repository;
    private readonly IEntityViewRepositoryContext<IInvoiceListView> _repositoryContext;
    private readonly IODataParser _odataParser;

    public ValidateFilteredInvoices(
        IInvoiceListViewRepository repository,
        IEntityViewRepositoryContext<IInvoiceListView> repositoryContext,
        IODataParser odataParser)
    {
        _repository = repository;
        _repositoryContext = repositoryContext;
        _odataParser = odataParser;
    }

    public async Task ExecuteAsync(string filter)
    {
        _repositoryContext.SetUIViewName("InvoiceListUI");

        IReadOnlyList<IInvoiceListView> invoices = await _repository.GetListAsync((query) => _odataParser.ApplyFilterAndSort(query, filter, null));

        // ...
    }
}