diff --git a/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php b/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php index 0d42a89..a60abf4 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Block/ViewsBlock.php @@ -39,6 +39,13 @@ class ViewsBlock extends BlockBase { protected $displayID; /** + * Whether to override the View title. + * + * @var bool + */ + protected $override_title; + + /** * Overrides \Drupal\Component\Plugin\PluginBase::__construct(). */ public function __construct(array $configuration, $plugin_id, array $plugin_definition, Block $entity) { @@ -49,6 +56,9 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi // Load the view. $this->view = views_get_view($name); $this->view->setDisplay($this->displayID); + if (!empty($configuration['override_title'])) { + $this->override_title = $configuration['override_title']; + } } /** @@ -63,20 +73,55 @@ public function blockAccess() { */ public function form($form, &$form_state) { $form = parent::form($form, $form_state); + $entity = $form_state['controller']->getEntity(); + $title = $this->view->getTitle(); + $view_name = $this->view->storage->label(); + $view_uri = $this->view->storage->uri(); + $display_url =$view_uri['path'] . '/edit/' . $this->displayID; + + // Provide a more meaningful block label and machine name. + if ($entity->isNew()) { + $form['label']['#value'] = $title ? $title : $view_name; + } + $form['label']['#weight'] = -2; + + // By default, the title of a Views block is set dynamically by the + // display. We give the user the option to override it with the block + // title set above, like any other block. + $form['override_title'] = array( + '#type' => 'checkbox', + '#weight' => -1, + '#title' => t('Display this title instead of the view title'), + '#default_value' => $this->override_title ? TRUE : FALSE, + ); + if (user_access('administer views')) { + $form['override_title']['#description'] = t('Edit the @viewname view to set the dynamic title.', array('@viewname' => $view_name, '@url' => $display_url)); + } + + // This functionality should be controlled in Views instead. + $form['label_display']['#default_value'] = TRUE; + $form['label_display']['#access'] = FALSE; - // Set the default label to '' so the views internal title is used. - $form['label']['#default_value'] = ''; - $form['label']['#access'] = FALSE; return $form; } /** + * {@inheritdoc} + */ + public function blockSubmit($form, &$form_state) { + $this->configuration['override_title'] = $form_state['values']['override_title']; + } + + /** * Implements \Drupal\block\BlockBase::blockBuild(). */ protected function blockBuild() { $output = $this->view->executeDisplay($this->displayID); - // Set the label to the title configured in the view. - $this->entity->set('label', filter_xss_admin($this->view->getTitle())); + // Set the label to the title configured in the view if it is not + // overridden by a custom block title. + if (!$this->override_title) { + $this->entity->set('label', filter_xss_admin($this->view->getTitle())); + } // Before returning the block output, convert it to a renderable array // with contextual links. $this->addContextualLinks($output);