diff --git a/core/modules/views/src/Plugin/Block/ViewsBlock.php b/core/modules/views/src/Plugin/Block/ViewsBlock.php
index 1e25133..5e29fe0 100644
--- a/core/modules/views/src/Plugin/Block/ViewsBlock.php
+++ b/core/modules/views/src/Plugin/Block/ViewsBlock.php
@@ -27,12 +27,12 @@ class ViewsBlock extends ViewsBlockBase {
* {@inheritdoc}
*/
public function build() {
- $this->view->display_handler->preBlockBuild($this);
+ $this->getView()->display_handler->preBlockBuild($this);
- if ($output = $this->view->buildRenderable($this->displayID)) {
+ if ($output = $this->getView()->buildRenderable($this->displayID)) {
// Override the label to the dynamic title configured in the view.
- if (empty($this->configuration['views_label']) && $this->view->getTitle()) {
- $output['#title'] = Xss::filterAdmin($this->view->getTitle());
+ if (empty($this->configuration['views_label']) && $this->getView()->getTitle()) {
+ $output['#title'] = Xss::filterAdmin($this->getView()->getTitle());
}
// Before returning the block output, convert it to a renderable array
@@ -65,7 +65,7 @@ public function defaultConfiguration() {
$settings = parent::defaultConfiguration();
if ($this->displaySet) {
- $settings += $this->view->display_handler->blockSettings($settings);
+ $settings += $this->getView()->display_handler->blockSettings($settings);
}
// Set custom cache settings.
@@ -81,7 +81,7 @@ public function defaultConfiguration() {
*/
public function blockForm($form, FormStateInterface $form_state) {
if ($this->displaySet) {
- return $this->view->display_handler->blockForm($this, $form, $form_state);
+ return $this->getView()->display_handler->blockForm($this, $form, $form_state);
}
return array();
@@ -92,7 +92,7 @@ public function blockForm($form, FormStateInterface $form_state) {
*/
public function blockValidate($form, FormStateInterface $form_state) {
if ($this->displaySet) {
- $this->view->display_handler->blockValidate($this, $form, $form_state);
+ $this->getView()->display_handler->blockValidate($this, $form, $form_state);
}
}
@@ -102,7 +102,7 @@ public function blockValidate($form, FormStateInterface $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);
+ $this->getView()->display_handler->blockSubmit($this, $form, $form_state);
}
}
@@ -110,8 +110,8 @@ public function blockSubmit($form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function getMachineNameSuggestion() {
- $this->view->setDisplay($this->displayID);
- return 'views_block__' . $this->view->storage->id() . '_' . $this->view->current_display;
+ $this->getView()->setDisplay($this->displayID);
+ return 'views_block__' . $this->getView()->storage->id() . '_' . $this->getView()->current_display;
}
}
diff --git a/core/modules/views/src/Plugin/Block/ViewsBlockBase.php b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php
index b87711f..4054ce9 100644
--- a/core/modules/views/src/Plugin/Block/ViewsBlockBase.php
+++ b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php
@@ -48,6 +48,7 @@
* @var \Drupal\Core\Session\AccountInterface
*/
protected $user;
+ protected $executableFactory;
/**
* Constructs a \Drupal\views\Plugin\Block\ViewsBlockBase object.
@@ -67,18 +68,31 @@
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ViewExecutableFactory $executable_factory, EntityStorageInterface $storage, AccountInterface $user) {
$this->pluginId = $plugin_id;
- $delta = $this->getDerivativeId();
- list($name, $this->displayID) = explode('-', $delta, 2);
+ $this->storage = $storage;
+ $this->executableFactory = $executable_factory;
+
// Load the view.
- $view = $storage->load($name);
- $this->view = $executable_factory->get($view);
- $this->displaySet = $this->view->setDisplay($this->displayID);
$this->user = $user;
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
+ * @return \Drupal\views\ViewExecutable
+ */
+ protected function getView() {
+ if (!isset($this->view)) {
+ $delta = $this->getDerivativeId();
+ list($name, $this->displayID) = explode('-', $delta, 2);
+ $view = $this->storage->load($name);
+ $this->view = $this->executableFactory->get($view);
+ $this->displaySet = $this->view->setDisplay($this->displayID);
+ }
+
+ return $this->view;
+ }
+
+ /**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
@@ -147,7 +161,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$form['views_label'] = array(
'#title' => $this->t('Title'),
'#type' => 'textfield',
- '#default_value' => $this->configuration['views_label'] ?: $this->view->getTitle(),
+ '#default_value' => $this->configuration['views_label'] ?: $this->getView()->getTitle(),
'#states' => array(
'visible' => array(
array(
@@ -158,8 +172,8 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#fieldset' => 'views_label_fieldset',
);
- if ($this->view->storage->access('edit') && \Drupal::moduleHandler()->moduleExists('views_ui')) {
- $form['views_label']['#description'] = $this->t('Changing the title here means it cannot be dynamically altered anymore. (Try changing it directly in @name.)', array('@url' => \Drupal::url('entity.view.edit_display_form', array('view' => $this->view->storage->id(), 'display_id' => $this->displayID)), '@name' => $this->view->storage->label()));
+ if ($this->getView()->storage->access('edit') && \Drupal::moduleHandler()->moduleExists('views_ui')) {
+ $form['views_label']['#description'] = $this->t('Changing the title here means it cannot be dynamically altered anymore. (Try changing it directly in @name.)', array('@url' => \Drupal::url('entity.view.edit_display_form', array('view' => $this->getView()->storage->id(), 'display_id' => $this->displayID)), '@name' => $this->getView()->storage->label()));
}
else {
$form['views_label']['#description'] = $this->t('Changing the title here means it cannot be dynamically altered anymore.');
diff --git a/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php b/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php
index f38d485..cb5b4bd 100644
--- a/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php
+++ b/core/modules/views/src/Plugin/Block/ViewsExposedFilterBlock.php
@@ -22,7 +22,7 @@ class ViewsExposedFilterBlock extends ViewsBlockBase {
* {@inheritdoc}
*/
public function build() {
- $output = $this->view->display_handler->viewExposedFormBlocks();
+ $output = $this->getView()->display_handler->viewExposedFormBlocks();
// Before returning the block output, convert it to a renderable array with
// contextual links.
$this->addContextualLinks($output, 'exposed_filter');