Chris@0: view->display_handler->preBlockBuild($this); Chris@0: Chris@0: $args = []; Chris@0: foreach ($this->view->display_handler->getHandlers('argument') as $argument_name => $argument) { Chris@0: // Initialize the argument value. Work around a limitation in Chris@0: // \Drupal\views\ViewExecutable::_buildArguments() that skips processing Chris@0: // later arguments if an argument with default action "ignore" and no Chris@0: // argument is provided. Chris@0: $args[$argument_name] = $argument->options['default_action'] == 'ignore' ? 'all' : NULL; Chris@0: Chris@0: if (!empty($this->context[$argument_name])) { Chris@0: if ($value = $this->context[$argument_name]->getContextValue()) { Chris@0: Chris@0: // Context values are often entities, but views arguments expect to Chris@0: // receive just the entity ID, convert it. Chris@0: if ($value instanceof EntityInterface) { Chris@0: $value = $value->id(); Chris@0: } Chris@0: $args[$argument_name] = $value; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: // We ask ViewExecutable::buildRenderable() to avoid creating a render cache Chris@0: // entry for the view output by passing FALSE, because we're going to cache Chris@0: // the whole block instead. Chris@0: if ($output = $this->view->buildRenderable($this->displayID, array_values($args), FALSE)) { Chris@0: // Before returning the block output, convert it to a renderable array Chris@0: // with contextual links. Chris@0: $this->addContextualLinks($output); Chris@0: Chris@0: // Block module expects to get a final render array, without another Chris@0: // top-level #pre_render callback. So, here we make sure that Views' Chris@0: // #pre_render callback has already been applied. Chris@0: $output = View::preRenderViewElement($output); Chris@0: Chris@0: // Override the label to the dynamic title configured in the view. Chris@0: if (empty($this->configuration['views_label']) && $this->view->getTitle()) { Chris@0: $output['#title'] = ['#markup' => $this->view->getTitle(), '#allowed_tags' => Xss::getHtmlTagList()]; Chris@0: } Chris@0: Chris@0: // When view_build is empty, the actual render array output for this View Chris@0: // is going to be empty. In that case, return just #cache, so that the Chris@0: // render system knows the reasons (cache contexts & tags) why this Views Chris@0: // block is empty, and can cache it accordingly. Chris@0: if (empty($output['view_build'])) { Chris@0: $output = ['#cache' => $output['#cache']]; Chris@0: } Chris@0: Chris@0: return $output; Chris@0: } Chris@0: Chris@0: return []; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getConfiguration() { Chris@0: $configuration = parent::getConfiguration(); Chris@0: Chris@0: // Set the label to the static title configured in the view. Chris@0: if (!empty($configuration['views_label'])) { Chris@0: $configuration['label'] = $configuration['views_label']; Chris@0: } Chris@0: Chris@0: return $configuration; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function defaultConfiguration() { Chris@0: $settings = parent::defaultConfiguration(); Chris@0: Chris@0: if ($this->displaySet) { Chris@0: $settings += $this->view->display_handler->blockSettings($settings); Chris@0: } Chris@0: Chris@0: // Set custom cache settings. Chris@0: if (isset($this->pluginDefinition['cache'])) { Chris@0: $settings['cache'] = $this->pluginDefinition['cache']; Chris@0: } Chris@0: Chris@0: return $settings; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function blockForm($form, FormStateInterface $form_state) { Chris@0: if ($this->displaySet) { Chris@0: return $this->view->display_handler->blockForm($this, $form, $form_state); Chris@0: } Chris@0: Chris@0: return []; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function blockValidate($form, FormStateInterface $form_state) { Chris@0: if ($this->displaySet) { Chris@0: $this->view->display_handler->blockValidate($this, $form, $form_state); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function blockSubmit($form, FormStateInterface $form_state) { Chris@0: parent::blockSubmit($form, $form_state); Chris@0: if ($this->displaySet) { Chris@0: $this->view->display_handler->blockSubmit($this, $form, $form_state); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getMachineNameSuggestion() { Chris@0: $this->view->setDisplay($this->displayID); Chris@0: return 'views_block__' . $this->view->storage->id() . '_' . $this->view->current_display; Chris@0: } Chris@0: Chris@0: }