The plugin that handles an EntityReference display.
"entity_reference_display" is a custom property, used with views_get_applicable_views() to retrieve all views with a 'Entity Reference' display.
@Plugin(
id = "entity_reference",
title = @Translation("Entity Reference"),
admin = @Translation("Entity Reference Source"),
help = @Translation("Selects referenceable entities for an entity reference field."),
theme = "views_view",
uses_hook_menu = FALSE,
entity_reference_display = TRUE
)
Expanded class hierarchy of EntityReference
class EntityReference extends DisplayPluginBase {
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$useAJAX.
*/
protected $usesAJAX = FALSE;
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesPager.
*/
protected $usesPager = FALSE;
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesAttachments.
*/
protected $usesAttachments = FALSE;
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::defineOptions().
*/
protected function defineOptions() {
$options = parent::defineOptions();
// Force the style plugin to 'entity_reference_style' and the row plugin to
// 'fields'.
$options['style']['contains']['type'] = array(
'default' => 'entity_reference',
);
$options['defaults']['default']['style'] = FALSE;
$options['row']['contains']['type'] = array(
'default' => 'entity_reference',
);
$options['defaults']['default']['row'] = FALSE;
// Make sure the query is not cached.
$options['defaults']['default']['cache'] = FALSE;
// Set the display title to an empty string (not used in this display type).
$options['title']['default'] = '';
$options['defaults']['default']['title'] = FALSE;
return $options;
}
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::optionsSummary().
*
* Disable 'cache' and 'title' so it won't be changed.
*/
public function optionsSummary(&$categories, &$options) {
parent::optionsSummary($categories, $options);
unset($options['query']);
unset($options['title']);
}
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::getType().
*/
protected function getType() {
return 'entity_reference';
}
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::execute().
*/
public function execute() {
return $this->view
->render($this->display['id']);
}
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::render().
*/
public function render() {
if (!empty($this->view->result) && $this->view->style_plugin
->evenEmpty()) {
return $this->view->style_plugin
->render($this->view->result);
}
return '';
}
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::usesExposed().
*/
public function usesExposed() {
return FALSE;
}
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::query().
*/
public function query() {
if (!empty($this->view->live_preview)) {
return;
}
// Make sure the id field is included in the results.
$id_field = $this->view->storage
->get('base_field');
$this->id_field_alias = $this->view->query
->addField($this->view->storage
->get('base_table'), $id_field);
$options = $this
->getOption('entity_reference_options');
// Restrict the autocomplete options based on what's been typed already.
if (isset($options['match'])) {
$style_options = $this
->getOption('style');
$value = db_like($options['match']) . '%';
if ($options['match_operator'] != 'STARTS_WITH') {
$value = '%' . $value;
}
// Multiple search fields are OR'd together.
$conditions = db_or();
// Build the condition using the selected search fields.
foreach ($style_options['options']['search_fields'] as $field_alias) {
if (!empty($field_alias)) {
// Get the table and field names for the checked field.
$field = $this->view->query->fields[$this->view->field[$field_alias]->field_alias];
// Add an OR condition for the field.
$conditions
->condition($field['table'] . '.' . $field['field'], $value, 'LIKE');
}
}
$this->view->query
->addWhere(0, $conditions);
}
// Add an IN condition for validation.
if (!empty($options['ids'])) {
$this->view->query
->addWhere(0, $id_field, $options['ids']);
}
$this->view
->setItemsPerPage($options['limit']);
}
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::validate().
*/
public function validate() {
$errors = parent::validate();
// Verify that search fields are set up.
$style = $this
->getOption('style');
if (!isset($style['options']['search_fields'])) {
$errors[] = t('Display "@display" needs a selected search fields to work properly. See the settings for the Entity Reference list format.', array(
'@display' => $this->display['display_title'],
));
}
else {
// Verify that the search fields used actually exist.
$fields = array_keys($this->handlers['field']);
foreach ($style['options']['search_fields'] as $field_alias => $enabled) {
if ($enabled && !in_array($field_alias, $fields)) {
$errors[] = t('Display "@display" uses field %field as search field, but the field is no longer present. See the settings for the Entity Reference list format.', array(
'@display' => $this->display['display_title'],
'%field' => $field_alias,
));
}
}
}
return $errors;
}
}
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 area plugins. | 2 |
DisplayPluginBase:: |
protected | property | Whether the display allows the use of a 'more' link or not. | 1 |
DisplayPluginBase:: |
protected | property |
Overrides Drupal\views\Plugin\Plugin::$usesOptions. Overrides PluginBase:: |
1 |
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 |
Provide the default form for setting options. Overrides PluginBase:: |
4 |
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:: |
public | function | Determine if this display should display the exposed filters widgets, so the view will know whether or not to render them. | 2 |
DisplayPluginBase:: |
public | function | If this display creates a page with a menu item, implement it here. | 1 |
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 | Return the base path to use for this display. | 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 | Check to see if the display has a 'path' field. | 1 |
DisplayPluginBase:: |
public | function | 2 | |
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:: |
function | Fully render the display for the purposes of a live preview or some other AJAXy reason. | 3 | |
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 |
Perform any necessary changes to the form values prior to storage.
There is no need for this function to actually store the data. Overrides PluginBase:: |
4 |
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 |
Validate the options form. Overrides PluginBase:: |
2 |
DisplayPluginBase:: |
public | function | Render the exposed form as block. | |
EntityReference:: |
protected | property |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$useAJAX. Overrides DisplayPluginBase:: |
|
EntityReference:: |
protected | property |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesAttachments. Overrides DisplayPluginBase:: |
|
EntityReference:: |
protected | property |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::$usesPager. Overrides DisplayPluginBase:: |
|
EntityReference:: |
protected | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::defineOptions(). Overrides DisplayPluginBase:: |
|
EntityReference:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::execute(). Overrides DisplayPluginBase:: |
|
EntityReference:: |
protected | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::getType(). Overrides DisplayPluginBase:: |
|
EntityReference:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::optionsSummary(). Overrides DisplayPluginBase:: |
|
EntityReference:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::query(). Overrides DisplayPluginBase:: |
|
EntityReference:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::render(). Overrides DisplayPluginBase:: |
|
EntityReference:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::usesExposed(). Overrides DisplayPluginBase:: |
|
EntityReference:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::validate(). Overrides DisplayPluginBase:: |
|
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:: |