Broken.php

Same filename in this branch
  1. 10 core/modules/views/src/Plugin/views/sort/Broken.php
  2. 10 core/modules/views/src/Plugin/views/field/Broken.php
  3. 10 core/modules/views/src/Plugin/views/relationship/Broken.php
  4. 10 core/modules/views/src/Plugin/views/filter/Broken.php
  5. 10 core/modules/views/src/Plugin/views/area/Broken.php
  6. 10 core/modules/views/src/Plugin/views/argument/Broken.php
  7. 10 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/Broken.php
Same filename in other branches
  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
  8. 9 core/lib/Drupal/Core/Block/Plugin/Block/Broken.php
  9. 8.9.x core/modules/views/src/Plugin/views/sort/Broken.php
  10. 8.9.x core/modules/views/src/Plugin/views/field/Broken.php
  11. 8.9.x core/modules/views/src/Plugin/views/relationship/Broken.php
  12. 8.9.x core/modules/views/src/Plugin/views/filter/Broken.php
  13. 8.9.x core/modules/views/src/Plugin/views/area/Broken.php
  14. 8.9.x core/modules/views/src/Plugin/views/argument/Broken.php
  15. 8.9.x core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/Broken.php
  16. 8.9.x 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\Attribute\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 Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Defines a fallback plugin for missing block plugins.
 */
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 install 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.