class Analyzer (View source)

This tool is a small plugin manager to perform analysis on a view and report results to the user. This tool is meant to let modules that provide data to Views also help users properly use that data by detecting invalid configurations. Views itself comes with only a small amount of analysis tools, but more could easily be added either by modules or as patches to Views itself.

Properties

protected ModuleHandlerInterface $moduleHandler

A module handler that invokes the 'views_analyze' hook.

Methods

__construct(ModuleHandlerInterface $module_handler)

Constructs an Analyzer object.

array
getMessages(ViewExecutable $view)

Analyzes a review and return the results.

formatMessages(array $messages)

Formats the analyze result into a message string.

static array
formatMessage(string $message, string $type = 'error')

Formats an analysis message.

Details

__construct(ModuleHandlerInterface $module_handler)

Constructs an Analyzer object.

Parameters

ModuleHandlerInterface $module_handler

The module handler that invokes the 'views_analyze' hook.

array getMessages(ViewExecutable $view)

Analyzes a review and return the results.

Parameters

ViewExecutable $view

The view to analyze.

Return Value

array

An array of analyze results organized into arrays keyed by 'ok', 'warning' and 'error'.

formatMessages(array $messages)

Formats the analyze result into a message string.

This is based upon the format of \Drupal\Core\Messenger\MessengerInterface::addMessage() which uses separate boxes for "ok", "warning" and "error".

Parameters

array $messages

static array formatMessage(string $message, string $type = 'error')

Formats an analysis message.

This tool should be called by any module responding to the analyze hook to properly format the message. It is usually used in the form:

Parameters

string $message

The message.

string $type

The type of message. This should be "ok", "warning" or "error". Other values can be used but how they are treated by the output routine is undefined.

Return Value

array

A single formatted message, consisting of a key message and a key type.