ContextInspector.php in Context 8.4
File
modules/context_ui/src/Plugin/Block/ContextInspector.php
View source
<?php
namespace Drupal\context_ui\Plugin\Block;
use Drupal\Core\Block\BlockBase;
class ContextInspector extends BlockBase {
public function getCacheMaxAge() {
return 0;
}
public function build() {
$moduleHandler = \Drupal::service('module_handler');
$module = $moduleHandler
->moduleExists('devel');
$permission = \Drupal::currentUser()
->hasPermission('access devel information');
if ($module && $permission) {
$context_manager = \Drupal::service('context.manager');
$output = kpr($context_manager
->getActiveContexts(), TRUE);
}
elseif ($module && !$permission) {
$output = $this
->t('You do not have permissions to view debug content.');
}
elseif (!$module) {
$output = $this
->t('Please enable the devel module to use the context inspector.');
}
$build = [
'#type' => 'markup',
'#markup' => $output,
];
return isset($output) ? $build : [];
}
}