class ViewsQueryAlter implements ContainerInjectionInterface (View source)

internal  
 

Defines a class for altering views queries.

Properties

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager service.

protected EntityFieldManagerInterface $entityFieldManager

The entity field manager.

protected WorkspaceManagerInterface $workspaceManager

The workspace manager service.

protected ViewsData $viewsData

The views data.

protected ViewsHandlerManager $viewsJoinPluginManager

A plugin manager which handles instances of views join plugins.

protected LanguageManagerInterface $languageManager

The language manager.

Methods

__construct(EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, WorkspaceManagerInterface $workspace_manager, ViewsData $views_data, ViewsHandlerManager $views_join_plugin_manager, LanguageManagerInterface $language_manager)

Constructs a new ViewsQueryAlter instance.

static 
create(ContainerInterface $container)

Instantiates a new instance of this class.

alterQuery(ViewExecutable $view, QueryPluginBase $query)

Implements a hook bridge for hook_views_query_alter().

alterQueryForEntityType(Sql $query, EntityTypeInterface $entity_type)

Alters the entity type tables for a Views query.

string
ensureWorkspaceAssociationTable(string $entity_type_id, Sql $query, string $relationship)

Adds the 'workspace_association' table to a views query.

string
ensureRevisionTable(EntityTypeInterface $entity_type, Sql $query, string $relationship)

Adds the revision table of an entity type to a query object.

getRevisionTableJoin(string $relationship, string $table, string $field, string $workspace_association_table, EntityTypeInterface $entity_type)

Fetches a join for a revision table using the workspace_association table.

moveEntityTable(Sql $query, string $workspace_association_table, string $alias)

Moves a 'workspace_association' table to appear before the given alias.

Details

__construct(EntityTypeManagerInterface $entity_type_manager, EntityFieldManagerInterface $entity_field_manager, WorkspaceManagerInterface $workspace_manager, ViewsData $views_data, ViewsHandlerManager $views_join_plugin_manager, LanguageManagerInterface $language_manager)

Constructs a new ViewsQueryAlter instance.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager service.

EntityFieldManagerInterface $entity_field_manager

The entity field manager.

WorkspaceManagerInterface $workspace_manager

The workspace manager service.

ViewsData $views_data

The views data.

ViewsHandlerManager $views_join_plugin_manager

The views join plugin manager.

LanguageManagerInterface $language_manager

The language manager.

static create(ContainerInterface $container)

Instantiates a new instance of this class.

This is a factory method that returns a new instance of this class. The factory should pass any needed dependencies into the constructor of this class, but not the container itself. Every call to this method must return a new instance of this class; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this instance should use.

alterQuery(ViewExecutable $view, QueryPluginBase $query)

Implements a hook bridge for hook_views_query_alter().

Parameters

ViewExecutable $view
QueryPluginBase $query

See also

hook_views_query_alter()

protected alterQueryForEntityType(Sql $query, EntityTypeInterface $entity_type)

Alters the entity type tables for a Views query.

This should only be called after determining that this entity type is involved in the query, and that a non-default workspace is in use.

Parameters

Sql $query

The query plugin object for the query.

EntityTypeInterface $entity_type

The entity type definition.

protected string ensureWorkspaceAssociationTable(string $entity_type_id, Sql $query, string $relationship)

Adds the 'workspace_association' table to a views query.

Parameters

string $entity_type_id

The ID of the entity type to join.

Sql $query

The query plugin object for the query.

string $relationship

The primary table alias this table is related to.

Return Value

string

The alias of the 'workspace_association' table.

protected string ensureRevisionTable(EntityTypeInterface $entity_type, Sql $query, string $relationship)

Adds the revision table of an entity type to a query object.

Parameters

EntityTypeInterface $entity_type

The entity type definition.

Sql $query

The query plugin object for the query.

string $relationship

The name of the relationship.

Return Value

string

The alias of the relationship.

protected JoinPluginInterface getRevisionTableJoin(string $relationship, string $table, string $field, string $workspace_association_table, EntityTypeInterface $entity_type)

Fetches a join for a revision table using the workspace_association table.

Parameters

string $relationship

The relationship to use in the view.

string $table

The table name.

string $field

The field to join on.

string $workspace_association_table

The alias of the 'workspace_association' table joined to the main entity table.

EntityTypeInterface $entity_type

The entity type that is being queried.

Return Value

JoinPluginInterface

An adjusted views join object to add to the query.

Exceptions

PluginException

protected moveEntityTable(Sql $query, string $workspace_association_table, string $alias)

Moves a 'workspace_association' table to appear before the given alias.

Because Workspace chains possibly pre-existing tables onto the 'workspace_association' table, we have to ensure that the 'workspace_association' table appears in the query before the alias it's chained on or the SQL is invalid.

Parameters

Sql $query

The SQL query object.

string $workspace_association_table

The alias of the 'workspace_association' table.

string $alias

The alias of the table it needs to appear before.