PageTitleBlock.php

Same filename and directory in other branches
  1. 8.9.x core/lib/Drupal/Core/Block/Plugin/Block/PageTitleBlock.php
  2. 10 core/lib/Drupal/Core/Block/Plugin/Block/PageTitleBlock.php
  3. 11.x core/lib/Drupal/Core/Block/Plugin/Block/PageTitleBlock.php

Namespace

Drupal\Core\Block\Plugin\Block

File

core/lib/Drupal/Core/Block/Plugin/Block/PageTitleBlock.php

View source
<?php

namespace Drupal\Core\Block\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Block\TitleBlockPluginInterface;

/**
 * Provides a block to display the page title.
 *
 * @Block(
 *   id = "page_title_block",
 *   admin_label = @Translation("Page title"),
 *   forms = {
 *     "settings_tray" = FALSE,
 *   },
 * )
 */
class PageTitleBlock extends BlockBase implements TitleBlockPluginInterface {
    
    /**
     * The page title: a string (plain title) or a render array (formatted title).
     *
     * @var string|array
     */
    protected $title = '';
    
    /**
     * {@inheritdoc}
     */
    public function setTitle($title) {
        $this->title = $title;
        return $this;
    }
    
    /**
     * {@inheritdoc}
     */
    public function defaultConfiguration() {
        return [
            'label_display' => FALSE,
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function build() {
        return [
            '#type' => 'page_title',
            '#title' => $this->title,
        ];
    }

}

Classes

Title Deprecated Summary
PageTitleBlock Provides a block to display the page title.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.