ViewExecutable
class ViewExecutable (View source)
Represents a view as a whole.
An object to contain all of the data to generate a view, plus the member functions to build the view query, execute the query and render the output.
This class does not implement the Serializable interface since problems occurred when using the serialize method.
Properties
| View | $storage | The config entity in which the view is stored. |
|
| bool | $built | Whether or not the view has been built. |
|
| bool | $executed | Whether the view has been executed/query has been run. |
|
| array | $args | Any arguments that have been passed into the view. |
|
| array | $build_info | An array of build info. |
|
| protected bool | $ajaxEnabled | Whether this view uses AJAX. |
|
| ResultRow[] | $result | Where the results of a query will go. |
|
| protected int | $current_page | The current page. If the view uses pagination. |
|
| protected int | $items_per_page | The number of items per page. |
|
| protected int | $offset | The pager offset. |
|
| int | $total_rows | The total number of rows returned from the query. |
|
| array | $attachment_before | Attachments to place before the view. |
|
| array | $attachment_after | Attachments to place after the view. |
|
| array | $feedIcons | Feed icons attached to the view. |
|
| array | $exposed_data | All the form data from $form_state->getValues(). |
|
| protected array | $exposed_input | An array of input values from exposed forms. |
|
| array | $exposed_raw_input | Exposed widget input directly from the $form_state->getValues(). |
|
| ViewExecutable[] | $old_view | Used to store views that were previously running if we recurse. |
|
| ViewExecutable[] | $parent_views | To avoid recursion in views embedded into areas. |
|
| bool | $is_attachment | Whether this view is an attachment to another view. |
|
| string | $current_display | Identifier of the current display. |
|
| QueryPluginBase | $query | Where the $query object will reside. |
|
| PagerPluginBase | $pager | The used pager plugin used by the current executed view. |
|
| DisplayPluginBase | $display_handler | The current used display plugin. |
|
| DisplayPluginCollection | $displayHandlers | The list of used displays of the view. |
|
| StylePluginBase | $style_plugin | The current used style plugin. |
|
| RowPluginBase | $rowPlugin | The current used row plugin, if the style plugin supports row plugins. |
|
| int | $row_index | Stores the current active row while rendering. |
|
| Url | $override_url | Allow to override the url of the current view. |
|
| string | $override_path | Allow to override the path used for generated urls. |
|
| bool | $base_database | Allow to override the used database which is used for this query. |
|
| FieldPluginBase[] | $field | Stores the field handlers which are initialized on this view. |
|
| ArgumentPluginBase[] | $argument | Stores the argument handlers which are initialized on this view. |
|
| SortPluginBase[] | $sort | Stores the sort handlers which are initialized on this view. |
|
| FilterPluginBase[] | $filter | Stores the filter handlers which are initialized on this view. |
|
| RelationshipPluginBase[] | $relationship | Stores the relationship handlers which are initialized on this view. |
|
| AreaPluginBase[] | $header | Stores the area handlers for the header which are initialized on this view. |
|
| AreaPluginBase[] | $footer | Stores the area handlers for the footer which are initialized on this view. |
|
| AreaPluginBase[] | $empty | Stores the area handlers for the empty text which are initialized on this view. |
|
| protected Response | $response | Stores the current response object. |
|
| protected Request | $request | Stores the current request object. |
|
| bool | $inited | Does this view already have loaded its handlers. |
|
| string | $exposed_widgets | The rendered output of the exposed form. |
|
| bool | $preview | If this view has been previewed. |
|
| bool | $get_total_rows | Force the query to calculate the total number of results. |
|
| bool | $build_sort | Indicates if the sorts have been built. |
|
| array | $many_to_one_tables | Stores the many-to-one tables for performance. |
|
| string | $dom_id | A unique identifier which allows to update multiple views output via js. |
|
| array | $element | A render array container to store render related information. |
|
| protected AccountInterface | $user | The current user. |
|
| protected bool | $showAdminLinks | Should the admin links be shown on the rendered view. |
|
| protected ViewsData | $viewsData | The views data. |
|
| protected RouteProviderInterface | $routeProvider | The route provider. |
|
| protected EntityTypeInterface|false | $baseEntityType | The entity type of the base table, if available. |
|
| protected array | $serializationData | Holds all necessary data for proper unserialization. |
Methods
Constructs a new ViewExecutable object.
Returns the identifier.
Saves the view.
Sets the arguments for the view.
Expands the list of used cache contexts for the view.
Sets the current page for the pager.
Gets the current page from the pager.
Gets the items per page from the pager.
Sets the items per page on the pager.
Gets the pager offset from the pager.
Sets the offset on the pager.
Determines if the view uses a pager.
Sets whether or not AJAX should be used.
Determines whether or not AJAX should be used.
Sets the exposed filters input to an array.
Figures out what the exposed input for this view is.
Sets the display for this view and initializes the display handler.
Gets the first display that is accessible to the user.
Gets the current display plugin.
Sets the current display.
Creates a new display and a display handler instance for it.
Gets the current style plugin.
Finds and initializes the style plugin.
Acquires and attaches all of the handlers.
Gets the current pager plugin.
Initializes the pager.
Renders the pager, if necessary.
Creates a list of base tables to be used by the view.
Returns the entity type of the base table, if available.
Runs the preQuery() on all active handlers.
Runs the postExecute() on all active handlers.
Attaches the views handler for the specific type.
Builds all the arguments.
Gets the current query plugin.
Initializes the query object for the view.
Builds the query for the view.
Builds an individual set of handlers.
Executes the view's query.
Renders this view for a certain display.
Gets the cache tags associated with the executed view.
Builds the render array outline for the given display.
Executes the given display, with the given arguments.
Previews the given display, with the given arguments.
Runs attachments and lets the display do what it needs to before running.
Unsets the current view, mostly.
Runs attachment displays for the view.
Determines if the given user has access to the view.
Sets the used response object of the view.
Gets the response object used by the view.
Sets the request object.
Gets the request object.
Gets the view's current title.
Overrides the view's current title.
Forces the view to build a title.
Determines whether you can link to the view or a particular display.
Gets the Url object associated with the display handler.
Gets the base path used for this view.
Gets the current user.
Creates a duplicate ViewExecutable object.
Unsets references so that a $view object may be properly garbage collected.
Makes sure the view is completely valid.
Provides a list of views handler types used in a view.
Returns the valid types of plugins that can be used.
Adds an instance of a handler to the view.
Generates a unique ID for a handler instance.
Gets an array of handler instances for the current display.
Gets the configuration of a handler instance on a given display.
Sets the configuration of a handler instance on a given display.
Removes configuration for a handler instance on a given display.
Sets an option on a handler instance.
Enables admin links on the rendered view.
Returns whether admin links should be rendered on the view.
Merges all plugin default values for each display.
Provides a full array of possible theme functions to try for a given hook.
Determines if this view has form elements.
Gets dependencies for the view.
Magic method implementation to serialize the view executable.
Magic method implementation to unserialize the view executable.
Details
__construct(ViewEntityInterface $storage, AccountInterface $user, ViewsData $views_data, RouteProviderInterface $route_provider)
Constructs a new ViewExecutable object.
string|null
id()
Returns the identifier.
save()
Saves the view.
setArguments(array $args)
Sets the arguments for the view.
$this
addCacheContext(string $cache_context)
Expands the list of used cache contexts for the view.
setCurrentPage(int $page)
Sets the current page for the pager.
int
getCurrentPage()
Gets the current page from the pager.
int
getItemsPerPage()
Gets the items per page from the pager.
setItemsPerPage(int $items_per_page)
Sets the items per page on the pager.
int
getOffset()
Gets the pager offset from the pager.
setOffset(int $offset)
Sets the offset on the pager.
bool
usePager()
Determines if the view uses a pager.
setAjaxEnabled(bool $ajax_enabled)
Sets whether or not AJAX should be used.
If AJAX is used, paging, table sorting, and exposed filters will be fetched via an AJAX call rather than a page refresh.
bool
ajaxEnabled()
Determines whether or not AJAX should be used.
setExposedInput(string[] $filters)
Sets the exposed filters input to an array.
string[]
getExposedInput()
Figures out what the exposed input for this view is.
They will be taken from \Drupal::request()->query or from something previously set on the view.
true
initDisplay()
Sets the display for this view and initializes the display handler.
string
chooseDisplay(array|string $displays)
Gets the first display that is accessible to the user.
DisplayPluginBase
getDisplay()
Gets the current display plugin.
bool
setDisplay(string $display_id = NULL)
Sets the current display.
DisplayPluginBase
newDisplay(string $plugin_id = 'page', string $title = NULL, string $id = NULL)
Creates a new display and a display handler instance for it.
StylePluginBase
getStyle()
Gets the current style plugin.
bool
initStyle()
Finds and initializes the style plugin.
Note that arguments may have changed which style plugin we use, so check the view object first, then ask the display handler.
initHandlers()
Acquires and attaches all of the handlers.
PagerPluginBase
getPager()
Gets the current pager plugin.
initPager()
Initializes the pager.
Like style initialization, pager initialization is held until late to allow for overrides.
array|string
renderPager(string[] $exposed_input)
Renders the pager, if necessary.
array
getBaseTables()
Creates a list of base tables to be used by the view.
This is used primarily for the UI. The display must be already initialized.
EntityType|false
getBaseEntityType()
Returns the entity type of the base table, if available.
protected
_preQuery()
Runs the preQuery() on all active handlers.
protected
_postExecute()
Runs the postExecute() on all active handlers.
protected
_initHandler(string $key, array $info)
Attaches the views handler for the specific type.
protected bool
_buildArguments()
Builds all the arguments.
QueryPluginBase
getQuery()
Gets the current query plugin.
true
initQuery()
Initializes the query object for the view.
bool|null
build(string $display_id = NULL)
Builds the query for the view.
_build(string $key)
Builds an individual set of handlers.
This is an internal method.
bool
execute(string $display_id = NULL)
Executes the view's query.
array|null
render(string $display_id = NULL)
Renders this view for a certain display.
Note: You should better use just the preview function if you want to render a view.
string[]
getCacheTags()
Gets the cache tags associated with the executed view.
Note: The cache plugin controls the used tags, so you can override it, if needed.
array|null
buildRenderable(string $display_id = NULL, array $args = [], bool $cache = TRUE)
Builds the render array outline for the given display.
This render array has a #pre_render callback which will call ::executeDisplay in order to actually execute the view and then build the final render array structure.
array|null
executeDisplay(string $display_id = NULL, string[] $args = [])
Executes the given display, with the given arguments.
To be called externally by whatever mechanism invokes the view, such as a page callback, hook_block, etc.
This function should NOT be used by anything external as this returns data in the format specified by the display. It can also have other side effects that are only intended for the 'proper' use of the display, such as setting page titles.
If you simply want to view the display, use View::preview() instead.
array|null
preview($display_id = NULL, $args = [])
Previews the given display, with the given arguments.
To be called externally, probably by an AJAX handler of some flavor. Can also be called when views are embedded, as this guarantees normalized output.
This function does not do any access checks on the view. It is the responsibility of the caller to check $view->access() or implement other access logic. To render the view normally with access checks, use views_embed_view() instead.
preExecute(array $args = [])
Runs attachments and lets the display do what it needs to before running.
postExecute()
Unsets the current view, mostly.
attachDisplays()
Runs attachment displays for the view.
bool
access(string $displays = NULL, AccountInterface $account = NULL)
Determines if the given user has access to the view.
Note that this sets the display handler if it hasn't been set.
setResponse(Response $response)
Sets the used response object of the view.
Response
getResponse()
Gets the response object used by the view.
setRequest(Request $request)
Sets the request object.
Request
getRequest()
Gets the request object.
string|false
getTitle()
Gets the view's current title.
This can change depending upon how it was built.
true
setTitle($title)
Overrides the view's current title.
The tokens in the title gets replaced before rendering.
buildTitle()
Forces the view to build a title.
bool
hasUrl(array $args = NULL, string $display_id = NULL)
Determines whether you can link to the view or a particular display.
Some displays (e.g. block displays) do not have their own route, but may optionally provide a link to another display that does have a route.
Url
getUrl(array $args = NULL, string $display_id = NULL)
Gets the URL for the current view.
This URL will be adjusted for arguments.
Url
getUrlInfo(string $display_id = '')
Gets the Url object associated with the display handler.
string|false
getPath()
Gets the base path used for this view.
AccountInterface
getUser()
Gets the current user.
Views plugins can receive the current user in order to not need dependency injection.
createDuplicate()
Creates a duplicate ViewExecutable object.
Makes a copy of this view that has been sanitized of handlers, any runtime data, ID, and UUID.
destroy()
Unsets references so that a $view object may be properly garbage collected.
array
validate()
Makes sure the view is completely valid.
static array
getHandlerTypes()
Provides a list of views handler types used in a view.
This also provides some information about the views handler types.
static array
getPluginTypes($type = NULL)
Returns the valid types of plugins that can be used.
string
addHandler(string $display_id, string $type, string $table, string $field, array $options = [], string $id = NULL)
Adds an instance of a handler to the view.
Items may be fields, filters, sort criteria, or arguments.
static string
generateHandlerId(string $requested_id, array $existing_items)
Generates a unique ID for a handler instance.
These handler instances are typically fields, filters, sort criteria, or arguments.
array
getHandlers(string $type, string $display_id = NULL)
Gets an array of handler instances for the current display.
array|null
getHandler(string $display_id, string $type, string $id)
Gets the configuration of a handler instance on a given display.
setHandler(string $display_id, string $type, string $id, array|null $item)
Sets the configuration of a handler instance on a given display.
removeHandler(string $display_id, string $type, string $id)
Removes configuration for a handler instance on a given display.
setHandlerOption(string $display_id, string $type, string $id, string $option, mixed $value)
Sets an option on a handler instance.
Use this only if you have just 1 or 2 options to set; if you have many, consider getting the handler instance, adding the options and using set_item() directly.
setShowAdminLinks(bool $show_admin_links)
Enables admin links on the rendered view.
bool
getShowAdminLinks()
Returns whether admin links should be rendered on the view.
mergeDefaults()
Merges all plugin default values for each display.
array
buildThemeFunctions(string $hook)
Provides a full array of possible theme functions to try for a given hook.
bool
hasFormElements()
Determines if this view has form elements.
array
getDependencies()
Gets dependencies for the view.
array
__sleep()
Magic method implementation to serialize the view executable.
__wakeup()
Magic method implementation to unserialize the view executable.