ViewsBlock.php in Drupal 8
File
core/modules/views/src/Plugin/Block/ViewsBlock.php
View source
<?php
namespace Drupal\views\Plugin\Block;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Element\View;
use Drupal\Core\Entity\EntityInterface;
class ViewsBlock extends ViewsBlockBase {
public function build() {
$this->view->display_handler
->preBlockBuild($this);
$args = [];
foreach ($this->view->display_handler
->getHandlers('argument') as $argument_name => $argument) {
$args[$argument_name] = $argument->options['default_action'] == 'ignore' ? 'all' : NULL;
if (!empty($this->context[$argument_name])) {
if ($value = $this->context[$argument_name]
->getContextValue()) {
if ($value instanceof EntityInterface) {
$value = $value
->id();
}
$args[$argument_name] = $value;
}
}
}
if ($output = $this->view
->buildRenderable($this->displayID, array_values($args), FALSE)) {
$this
->addContextualLinks($output);
$output = View::preRenderViewElement($output);
if (empty($this->configuration['views_label']) && $this->view
->getTitle()) {
$output['#title'] = [
'#markup' => $this->view
->getTitle(),
'#allowed_tags' => Xss::getHtmlTagList(),
];
}
if (empty($output['view_build'])) {
$output = [
'#cache' => $output['#cache'],
];
}
return $output;
}
return [];
}
public function getConfiguration() {
$configuration = parent::getConfiguration();
if (!empty($configuration['views_label'])) {
$configuration['label'] = $configuration['views_label'];
}
return $configuration;
}
public function defaultConfiguration() {
$settings = parent::defaultConfiguration();
if ($this->displaySet) {
$settings += $this->view->display_handler
->blockSettings($settings);
}
if (isset($this->pluginDefinition['cache'])) {
$settings['cache'] = $this->pluginDefinition['cache'];
}
return $settings;
}
public function blockForm($form, FormStateInterface $form_state) {
if ($this->displaySet) {
return $this->view->display_handler
->blockForm($this, $form, $form_state);
}
return [];
}
public function blockValidate($form, FormStateInterface $form_state) {
if ($this->displaySet) {
$this->view->display_handler
->blockValidate($this, $form, $form_state);
}
}
public function blockSubmit($form, FormStateInterface $form_state) {
parent::blockSubmit($form, $form_state);
if ($this->displaySet) {
$this->view->display_handler
->blockSubmit($this, $form, $form_state);
}
}
public function getMachineNameSuggestion() {
$this->view
->setDisplay($this->displayID);
return 'views_block__' . $this->view->storage
->id() . '_' . $this->view->current_display;
}
}