Broken.php

Same filename in this branch
  1. 9 core/modules/views/src/Plugin/views/sort/Broken.php
  2. 9 core/modules/views/src/Plugin/views/field/Broken.php
  3. 9 core/modules/views/src/Plugin/views/relationship/Broken.php
  4. 9 core/modules/views/src/Plugin/views/filter/Broken.php
  5. 9 core/modules/views/src/Plugin/views/area/Broken.php
  6. 9 core/modules/views/src/Plugin/views/argument/Broken.php
  7. 9 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/Broken.php
Same filename in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/sort/Broken.php
  2. 8.9.x core/modules/views/src/Plugin/views/field/Broken.php
  3. 8.9.x core/modules/views/src/Plugin/views/relationship/Broken.php
  4. 8.9.x core/modules/views/src/Plugin/views/filter/Broken.php
  5. 8.9.x core/modules/views/src/Plugin/views/area/Broken.php
  6. 8.9.x core/modules/views/src/Plugin/views/argument/Broken.php
  7. 8.9.x core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/Broken.php
  8. 8.9.x core/lib/Drupal/Core/Block/Plugin/Block/Broken.php
  9. 10 core/modules/views/src/Plugin/views/sort/Broken.php
  10. 10 core/modules/views/src/Plugin/views/field/Broken.php
  11. 10 core/modules/views/src/Plugin/views/relationship/Broken.php
  12. 10 core/modules/views/src/Plugin/views/filter/Broken.php
  13. 10 core/modules/views/src/Plugin/views/area/Broken.php
  14. 10 core/modules/views/src/Plugin/views/argument/Broken.php
  15. 10 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/Broken.php
  16. 10 core/lib/Drupal/Core/Block/Plugin/Block/Broken.php
  17. 11.x core/modules/views/src/Plugin/views/sort/Broken.php
  18. 11.x core/modules/views/src/Plugin/views/field/Broken.php
  19. 11.x core/modules/views/src/Plugin/views/relationship/Broken.php
  20. 11.x core/modules/views/src/Plugin/views/filter/Broken.php
  21. 11.x core/modules/views/src/Plugin/views/area/Broken.php
  22. 11.x core/modules/views/src/Plugin/views/argument/Broken.php
  23. 11.x core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/Broken.php
  24. 11.x core/lib/Drupal/Core/Block/Plugin/Block/Broken.php

Namespace

Drupal\Core\Block\Plugin\Block

File

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

View source
<?php

namespace Drupal\Core\Block\Plugin\Block;

use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Block\BlockPluginTrait;
use Drupal\Core\Cache\CacheableDependencyTrait;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Defines a fallback plugin for missing block plugins.
 *
 * @Block(
 *   id = "broken",
 *   admin_label = @Translation("Broken/Missing"),
 *   category = @Translation("Block"),
 * )
 */
class Broken extends PluginBase implements BlockPluginInterface, ContainerFactoryPluginInterface {
    use BlockPluginTrait;
    use CacheableDependencyTrait;
    
    /**
     * The current user.
     *
     * @var \Drupal\Core\Session\AccountInterface
     */
    protected $currentUser;
    
    /**
     * Creates a Broken Block instance.
     *
     * @param array $configuration
     *   A configuration array containing information about the plugin instance.
     * @param string $plugin_id
     *   The plugin ID for the plugin instance.
     * @param mixed $plugin_definition
     *   The plugin implementation definition.
     * @param \Drupal\Core\Session\AccountInterface $current_user
     *   The current user.
     */
    public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountInterface $current_user) {
        parent::__construct($configuration, $plugin_id, $plugin_definition);
        $this->currentUser = $current_user;
    }
    
    /**
     * {@inheritdoc}
     */
    public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
        return new static($configuration, $plugin_id, $plugin_definition, $container->get('current_user'));
    }
    
    /**
     * {@inheritdoc}
     */
    public function build() {
        $build = [];
        if ($this->currentUser
            ->hasPermission('administer blocks')) {
            $build += $this->brokenMessage();
        }
        return $build;
    }
    
    /**
     * {@inheritdoc}
     */
    public function blockForm($form, FormStateInterface $form_state) {
        return $this->brokenMessage();
    }
    
    /**
     * Generate message with debugging information as to why the block is broken.
     *
     * @return array
     *   Render array containing debug information.
     */
    protected function brokenMessage() {
        $build['message'] = [
            '#markup' => $this->t('This block is broken or missing. You may be missing content or you might need to enable the original module.'),
        ];
        return $build;
    }

}

Classes

Title Deprecated Summary
Broken Defines a fallback plugin for missing block plugins.

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