The plugin that handles Data response callbacks for REST resources.
@Plugin(
id = "rest_export",
module = "rest",
title = @Translation("REST export"),
help = @Translation("Create a REST export resource."),
uses_route = TRUE,
admin = @Translation("REST export")
)
Expanded class hierarchy of RestExport
class RestExport extends PathPluginBase {
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesAJAX.
*/
protected $usesAJAX = FALSE;
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesPager.
*/
protected $usesPager = FALSE;
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesMore.
*/
protected $usesMore = FALSE;
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesAreas.
*/
protected $usesAreas = FALSE;
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesAreas.
*/
protected $usesOptions = FALSE;
/**
* Overrides the content type of the data response, if needed.
*
* @var string
*/
protected $contentType = 'json';
/**
* The mime type for the response.
*
* @var string
*/
protected $mimeType;
/**
* {@inheritdoc}
*/
public function initDisplay(ViewExecutable $view, array &$display, array &$options = NULL) {
parent::initDisplay($view, $display, $options);
$container = drupal_container();
$negotiation = $container
->get('content_negotiation');
$request = $container
->get('request');
$request_content_type = $negotiation
->getContentType($request);
// Only use the requested content type if it's not 'html'. If it is then
// default to 'json' to aid debugging.
// @todo Remove the need for this when we have better content negotiation.
if ($request_content_type != 'html') {
$this
->setContentType($request_content_type);
}
$this
->setMimeType($request
->getMimeType($this->contentType));
}
/**
* {@inheritdoc}
*/
protected function getType() {
return 'data';
}
/**
* {@inheritdoc}
*/
public function usesExposed() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function displaysExposed() {
return FALSE;
}
/**
* Sets the request content type.
*
* @param string $mime_type
* The response mime type. E.g. 'application/json'.
*/
public function setMimeType($mime_type) {
$this->mimeType = $mime_type;
}
/**
* Gets the mime type.
*
* This will return any overridden mime type, otherwise returns the mime type
* from the request.
*
* @return string
* The response mime type. E.g. 'application/json'.
*/
public function getMimeType() {
return $this->mimeType;
}
/**
* Sets the content type.
*
* @param string $content_type
* The content type machine name. E.g. 'json'.
*/
public function setContentType($content_type) {
$this->contentType = $content_type;
}
/**
* Gets the content type.
*
* @return string
* The content type machine name. E.g. 'json'.
*/
public function getContentType() {
return $this->contentType;
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
// Set the default style plugin to 'json'.
$options['style']['contains']['type']['default'] = 'serializer';
$options['row']['contains']['type']['default'] = 'data_entity';
$options['defaults']['default']['style'] = FALSE;
$options['defaults']['default']['row'] = FALSE;
// Remove css/exposed form settings, as they are not used for the data display.
unset($options['exposed_form']);
unset($options['exposed_block']);
unset($options['css_class']);
return $options;
}
/**
* {@inheritdoc}
*/
public function optionsSummary(&$categories, &$options) {
parent::optionsSummary($categories, $options);
unset($categories['page'], $categories['exposed']);
// Hide some settings, as they aren't useful for pure data output.
unset($options['show_admin_links'], $options['analyze-theme']);
$categories['path'] = array(
'title' => t('Path settings'),
'column' => 'second',
'build' => array(
'#weight' => -10,
),
);
$options['path']['category'] = 'path';
$options['path']['title'] = t('Path');
// Remove css/exposed form settings, as they are not used for the data
// display.
unset($options['exposed_form']);
unset($options['exposed_block']);
unset($options['css_class']);
}
/**
* {@inheritdoc}
*/
public function collectRoutes(RouteCollection $collection) {
parent::collectRoutes($collection);
$style_plugin = $this
->getPlugin('style');
// REST exports should only respond to get methods.
$requirements = array(
'_method' => 'GET',
);
// Format as a string using pipes as a delimeter.
$requirements['_format'] = implode('|', $style_plugin
->getFormats());
// Add the new requirements to each route.
foreach ($collection as $route) {
$route
->addRequirements($requirements);
}
}
/**
* {@inheritdoc}
*/
public function execute() {
parent::execute();
$output = $this->view
->render();
return new Response(drupal_render($output), 200, array(
'Content-type' => $this
->getMimeType(),
));
}
/**
* {@inheritdoc}
*/
public function render() {
$build = array();
$build['#markup'] = $this->view->style_plugin
->render();
// Wrap the output in a pre tag if this is for a live preview.
if (!empty($this->view->live_preview)) {
$build['#prefix'] = '<pre>';
$build['#markup'] = check_plain($build['#markup']);
$build['#suffix'] = '</pre>';
}
return $build;
}
/**
* {@inheritdoc}
*
* The DisplayPluginBase preview method assumes we will be returning a render
* array. The data plugin will already return the serialized string.
*/
public function preview() {
return $this->view
->render();
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContainerFactoryPluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
11 |
DisplayPluginBase:: |
property | Stores all available display extenders. | ||
DisplayPluginBase:: |
property | |||
DisplayPluginBase:: |
public | property | Stores the rendered output of the display. | |
DisplayPluginBase:: |
protected | property | An array of instantiated plugins used in this display. | |
DisplayPluginBase:: |
protected | property | Whether the display allows attachments. | 5 |
DisplayPluginBase:: |
property |
The top object of a view. Overrides PluginBase:: |
||
DisplayPluginBase:: |
public | function | Determines whether this display can use attachments. | |
DisplayPluginBase:: |
public | function | Determine if the user has access to this display of the view. | |
DisplayPluginBase:: |
public | function | Whether the display is actually using AJAX or not. | |
DisplayPluginBase:: |
public | function | Allow displays to attach to other views. | 2 |
DisplayPluginBase:: |
public | function | Displays the Change Theme form. | |
DisplayPluginBase:: |
public | function | Static member function to list which sections are defaultable and what items each section contains. | 1 |
DisplayPluginBase:: |
public | function |
Clears a plugin. Overrides PluginBase:: |
|
DisplayPluginBase:: |
protected | function | Format a list of theme templates for output by the theme info helper. | |
DisplayPluginBase:: |
public | function | Returns to tokens for arguments. | |
DisplayPluginBase:: |
public | function | Provide some helpful text for the arguments. The result should contain of an array with | 1 |
DisplayPluginBase:: |
public | function | Find out all displays which are attached to this display. | |
DisplayPluginBase:: |
public | function | Retrieves a list of fields for the current display. | |
DisplayPluginBase:: |
public | function | Get the handler object for a single handler. | |
DisplayPluginBase:: |
public | function | Get a full array of handlers for $type. This caches them. | |
DisplayPluginBase:: |
public | function | Check to see which display to use when creating links within a view using this display. | |
DisplayPluginBase:: |
public | function | Intelligently get an option either from this display or from the default display, if directed to do so. | |
DisplayPluginBase:: |
public | function | Provide some helpful text for pagers. | 1 |
DisplayPluginBase:: |
public | function | Get the instance of a plugin, for example style or row. | |
DisplayPluginBase:: |
public | function | Provide the block system with any exposed widget blocks for this display. | |
DisplayPluginBase:: |
public | function | ||
DisplayPluginBase:: |
public | function | Determine if this display is the 'default' display which contains fallback settings | 1 |
DisplayPluginBase:: |
public | function | Determine if a given option is set to use the default display or the current display | |
DisplayPluginBase:: |
public | function | Whether the display is enabled. | |
DisplayPluginBase:: |
public | function | Check if the provided identifier is unique. | |
DisplayPluginBase:: |
public | function | Whether the display is using the 'more' link or not. | |
DisplayPluginBase:: |
public | function | Whether the display is using a pager or not. | |
DisplayPluginBase:: |
public | function | Merges default values for all plugin types. | |
DisplayPluginBase:: |
protected | function | Merges handlers default values. | |
DisplayPluginBase:: |
protected | function | Merges plugins default values. | |
DisplayPluginBase:: |
public | function | Because forms may be split up into sections, this provides an easy URL to exactly the right section. Don't override this. | |
DisplayPluginBase:: |
public | function | If override/revert was clicked, perform the proper toggle. | |
DisplayPluginBase:: |
public | function | Set an option and force it to be an override. | |
DisplayPluginBase:: |
public | function | Set up any variables on the view prior to execution. These are separated from execute because they are extremely common and unlikely to be overridden on an individual display. | |
DisplayPluginBase:: |
public | function |
Inject anything into the query that the display handler needs. Overrides PluginBase:: |
1 |
DisplayPluginBase:: |
public | function | Reacts on deleting a display. | 1 |
DisplayPluginBase:: |
public | function | Render one of the available areas. | |
DisplayPluginBase:: |
public | function | Not all display plugins will support filtering | |
DisplayPluginBase:: |
public | function | Render the 'more' link | |
DisplayPluginBase:: |
public | function | Not all display plugins will suppert pager rendering. | 1 |
DisplayPluginBase:: |
public | function | Submit hook to clear Drupal's theme registry (thereby triggering a templates rescan). | |
DisplayPluginBase:: |
public | function | Intelligently set an option either from this display or from the default display, if directed to do so. | |
DisplayPluginBase:: |
public | function | Flip the override setting for the given section. | |
DisplayPluginBase:: |
public | function | Does the display have groupby enabled? | |
DisplayPluginBase:: |
public | function | Should the enabled display more link be shown when no more items? | |
DisplayPluginBase:: |
public | function | Does the display have custom link text? | |
DisplayPluginBase:: |
public | function | Whether the display allows the use of AJAX or not. | 2 |
DisplayPluginBase:: |
public | function | Returns whether the display can use areas. | 2 |
DisplayPluginBase:: |
public | function | Returns whether the display can use attachments. | 5 |
DisplayPluginBase:: |
public | function | Check to see if the display needs a breadcrumb | 1 |
DisplayPluginBase:: |
public | function | Check to see if the display can put the exposed formin a block. | |
DisplayPluginBase:: |
public | function | Determine if the display's style uses fields. | |
DisplayPluginBase:: |
public | function | Check to see if the display has some need to link to another display. | 1 |
DisplayPluginBase:: |
public | function | Whether the display allows the use of a 'more' link or not. | 1 |
DisplayPluginBase:: |
public | function | Whether the display allows the use of a pager or not. | 4 |
DisplayPluginBase:: |
public | function |
Make sure the display and all associated handlers are valid. Overrides PluginBase:: |
2 |
DisplayPluginBase:: |
public | function | Render the exposed form as block. | |
PathPluginBase:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::buildOptionsForm(). Overrides DisplayPluginBase:: |
2 |
PathPluginBase:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::executeHookMenu(). Overrides DisplayPluginBase:: |
|
PathPluginBase:: |
public | function |
Return the base path to use for this display. Overrides DisplayPluginBase:: |
|
PathPluginBase:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::hasPath(). Overrides DisplayPluginBase:: |
|
PathPluginBase:: |
protected | function | Determines if this display's path is a default tab. | |
PathPluginBase:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::submitOptionsForm(). Overrides DisplayPluginBase:: |
2 |
PathPluginBase:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::validateOptionsForm(). Overrides DisplayPluginBase:: |
1 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
public | property | Plugins's definition | |
PluginBase:: |
public | property | The display object this plugin is for. | |
PluginBase:: |
public | property | Options for this plugin will be held here. | |
PluginBase:: |
protected | property | The plugin implementation definition. | |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
public | function | Returns an array of available token replacements. | |
PluginBase:: |
public | function |
Returns the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function |
Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Adds elements for available core tokens to a form. | |
PluginBase:: |
public | function | Returns a string with any core tokens replaced. | |
PluginBase:: |
public | function | Initialize the plugin. | 8 |
PluginBase:: |
public | function | Return the human readable name of the display. | |
PluginBase:: |
protected | function | Fills up the options of the plugin with defaults. | |
PluginBase:: |
public | function | Returns the summary of the settings in the display. | 6 |
PluginBase:: |
public | function | Provide a full list of possible theme templates used by this style. | 1 |
PluginBase:: |
public | function | Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away. | |
PluginBase:: |
public | function | Returns the usesOptions property. | 8 |
PluginBase:: |
public | function |
Constructs a Plugin object. Overrides PluginBase:: |
|
RestExport:: |
protected | property | Overrides the content type of the data response, if needed. | |
RestExport:: |
protected | property | The mime type for the response. | |
RestExport:: |
protected | property |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesAJAX. Overrides DisplayPluginBase:: |
|
RestExport:: |
protected | property |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesAreas. Overrides DisplayPluginBase:: |
|
RestExport:: |
protected | property |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesMore. Overrides DisplayPluginBase:: |
|
RestExport:: |
protected | property |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesAreas. Overrides DisplayPluginBase:: |
|
RestExport:: |
protected | property |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesPager. Overrides DisplayPluginBase:: |
|
RestExport:: |
public | function |
Adds the route entry of a view to the collection. Overrides PathPluginBase:: |
|
RestExport:: |
protected | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase:defineOptions(). Overrides PathPluginBase:: |
|
RestExport:: |
public | function |
Determine if this display should display the exposed
filters widgets, so the view will know whether or not
to render them. Overrides DisplayPluginBase:: |
|
RestExport:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::execute(). Overrides PathPluginBase:: |
|
RestExport:: |
public | function | Gets the content type. | |
RestExport:: |
public | function | Gets the mime type. | |
RestExport:: |
protected | function |
Returns the display type that this display requires. Overrides DisplayPluginBase:: |
|
RestExport:: |
public | function |
Overrides DisplayPluginBase:: |
|
RestExport:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::optionsSummary(). Overrides PathPluginBase:: |
|
RestExport:: |
public | function |
The DisplayPluginBase preview method assumes we will be returning a render
array. The data plugin will already return the serialized string. Overrides DisplayPluginBase:: |
|
RestExport:: |
public | function |
Render this display. Overrides DisplayPluginBase:: |
|
RestExport:: |
public | function | Sets the content type. | |
RestExport:: |
public | function | Sets the request content type. | |
RestExport:: |
public | function |
Determine if this display uses exposed filters, so the view
will know whether or not to build them. Overrides DisplayPluginBase:: |