The plugin that handles a block.
@Plugin(
id = "block",
module = "block",
title = @Translation("Block"),
help = @Translation("Display the view as a block."),
theme = "views_view",
uses_hook_block = TRUE,
contextual_links_locations = {"block"},
admin = @Translation("Block")
)
Expanded class hierarchy of Block
class Block extends DisplayPluginBase {
/**
* Whether the display allows attachments.
*
* @var bool
*/
protected $usesAttachments = TRUE;
protected function defineOptions() {
$options = parent::defineOptions();
$options['block_description'] = array(
'default' => '',
'translatable' => TRUE,
);
$options['block_caching'] = array(
'default' => DRUPAL_NO_CACHE,
);
return $options;
}
/**
* The display block handler returns the structure necessary for a block.
*/
public function execute() {
// Prior to this being called, the $view should already be set to this
// display, and arguments should be set on the view.
$element = $this->view
->render();
if (!empty($this->view->result) || $this
->getOption('empty') || !empty($this->view->style_plugin->definition['even empty'])) {
return drupal_render($element);
}
}
/**
* Provide the summary for page options in the views UI.
*
* This output is returned as an array.
*/
public function optionsSummary(&$categories, &$options) {
parent::optionsSummary($categories, $options);
$categories['block'] = array(
'title' => t('Block settings'),
'column' => 'second',
'build' => array(
'#weight' => -10,
),
);
$block_description = strip_tags($this
->getOption('block_description'));
if (empty($block_description)) {
$block_description = t('None');
}
$options['block_description'] = array(
'category' => 'block',
'title' => t('Block name'),
'value' => views_ui_truncate($block_description, 24),
);
$types = $this
->blockCachingModes();
$options['block_caching'] = array(
'category' => 'other',
'title' => t('Block caching'),
'value' => $types[$this
->getCacheType()],
);
}
/**
* Provide a list of core's block caching modes.
*/
protected function blockCachingModes() {
return array(
DRUPAL_NO_CACHE => t('Do not cache'),
DRUPAL_CACHE_GLOBAL => t('Cache once for everything (global)'),
DRUPAL_CACHE_PER_PAGE => t('Per page'),
DRUPAL_CACHE_PER_ROLE => t('Per role'),
DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGE => t('Per role per page'),
DRUPAL_CACHE_PER_USER => t('Per user'),
DRUPAL_CACHE_PER_USER | DRUPAL_CACHE_PER_PAGE => t('Per user per page'),
);
}
/**
* Provide a single method to figure caching type, keeping a sensible default
* for when it's unset.
*/
public function getCacheType() {
$cache_type = $this
->getOption('block_caching');
if (empty($cache_type)) {
$cache_type = DRUPAL_NO_CACHE;
}
return $cache_type;
}
/**
* Provide the default form for setting options.
*/
public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
switch ($form_state['section']) {
case 'block_description':
$form['#title'] .= t('Block admin description');
$form['block_description'] = array(
'#type' => 'textfield',
'#description' => t('This will appear as the name of this block in administer >> structure >> blocks.'),
'#default_value' => $this
->getOption('block_description'),
);
break;
case 'block_caching':
$form['#title'] .= t('Block caching type');
$form['block_caching'] = array(
'#type' => 'radios',
'#description' => t("This sets the default status for Drupal's built-in block caching method; this requires that caching be turned on in block administration, and be careful because you have little control over when this cache is flushed."),
'#options' => $this
->blockCachingModes(),
'#default_value' => $this
->getCacheType(),
);
break;
case 'exposed_form_options':
$this->view
->initHandlers();
if (!$this
->usesExposed() && parent::usesExposed()) {
$form['exposed_form_options']['warning'] = array(
'#weight' => -10,
'#markup' => '<div class="messages messages--warning">' . t('Exposed filters in block displays require "Use AJAX" to be set to work correctly.') . '</div>',
);
}
}
}
/**
* Perform any necessary changes to the form values prior to storage.
* There is no need for this function to actually store the data.
*/
public function submitOptionsForm(&$form, &$form_state) {
parent::submitOptionsForm($form, $form_state);
switch ($form_state['section']) {
case 'block_description':
$this
->setOption('block_description', $form_state['values']['block_description']);
break;
case 'block_caching':
$this
->setOption('block_caching', $form_state['values']['block_caching']);
break;
}
}
/**
* Block views use exposed widgets only if AJAX is set.
*/
public function usesExposed() {
if ($this
->ajaxEnabled()) {
return parent::usesExposed();
}
return FALSE;
}
/**
* Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::remove().
*/
public function remove() {
parent::remove();
$plugin_id = 'views_block:' . $this->view->storage
->id() . '-' . $this->display['id'];
foreach (entity_load_multiple_by_properties('block', array(
'plugin' => $plugin_id,
)) as $block) {
$block
->delete();
}
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Block:: |
protected | property |
Whether the display allows attachments. Overrides DisplayPluginBase:: |
|
Block:: |
protected | function | Provide a list of core's block caching modes. | |
Block:: |
public | function |
Provide the default form for setting options. Overrides DisplayPluginBase:: |
|
Block:: |
protected | function |
Information about options for all kinds of purposes will be held here.
@code
'option_name' => array( Overrides DisplayPluginBase:: |
|
Block:: |
public | function |
The display block handler returns the structure necessary for a block. Overrides DisplayPluginBase:: |
|
Block:: |
public | function | Provide a single method to figure caching type, keeping a sensible default for when it's unset. | |
Block:: |
public | function |
Provide the summary for page options in the views UI. Overrides DisplayPluginBase:: |
|
Block:: |
public | function |
Overrides \Drupal\views\Plugin\views\display\DisplayPluginBase::remove(). Overrides DisplayPluginBase:: |
|
Block:: |
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 DisplayPluginBase:: |
|
Block:: |
public | function |
Block views use exposed widgets only if AJAX is set. Overrides DisplayPluginBase:: |
|
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 the use of AJAX or not. | 2 |
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:: |
protected | property | Whether the display allows the use of a pager or not. | 4 |
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:: |
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:: |
protected | function | Returns the display type that this display requires. | 4 |
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 |
Inject anything into the query that the display handler needs. Overrides PluginBase:: |
1 |
DisplayPluginBase:: |
public | function | Render this display. | 3 |
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 |
Validate the options form. Overrides PluginBase:: |
2 |
DisplayPluginBase:: |
public | function | Render the exposed form as block. | |
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:: |