Skip to content

Instantly share code, notes, and snippets.

@hissy hissy/app.php
Last active Jan 2, 2019

Embed
What would you like to do?
[concrete5] [Debug tool] Tooltip to display block detail
<?php
// application/bootstrap/app.php
$dh = $app->make('helper/concrete/dashboard');
$director = $app->make('director');
$director->addListener('on_before_render', function ($event) use ($dh) {
/** @var \Concrete\Core\View\View $view */
$view = $event->getArgument('view');
$page = \Concrete\Core\Page\Page::getCurrentPage();
$p = new \Concrete\Core\Permission\Checker($page);
if ($p->canViewToolbar() && !$dh->inDashboard()) {
$view->addHeaderItem('<style>.block-tooltip-wrapper:hover {-webkit-box-shadow: 0px 0px 3px 0px rgba(0,0,0,0.8);box-shadow: 0px 0px 3px 0px rgba(0,0,0,0.8);}</style>');
$view->addFooterItem('<script>$(function(){$(".block-tooltip-wrapper").tooltip()});</script>');
}
});
$director->addListener('on_block_output', function ($event) use ($dh) {
/** @var \Concrete\Core\Block\Events\BlockOutput $event */
$page = \Concrete\Core\Page\Page::getCurrentPage();
$p = new \Concrete\Core\Permission\Checker($page);
if ($p->canViewToolbar() && !$dh->inDashboard()) {
if (is_object($page) && !$page->isEditMode()) {
$contents = $event->getContents();
$block = $event->getBlock();
$btHandle = $block->getBlockTypeHandle();
$placement = 'bottom';
if ($btHandle == 'core_stack_display' || $btHandle == 'core_scrapbook_display' || $btHandle == 'core_area_layout') {
$placement = 'top';
}
$tooltip = sprintf('Block Type (%s) ', $btHandle);
$tooltip .= sprintf('Block ID (%s) ', $block->getBlockID());
$tooltip .= sprintf('Area Handle (%s) ', $block->getAreaHandle());
$tooltip .= sprintf('Block Collection ID (%s) ', $block->getBlockCollectionID());
$contents = sprintf('<div class="block-tooltip-wrapper %s" data-toggle="tooltip" data-placement="%s" title="%s">%s</div>', $btHandle, $placement, $tooltip, $contents);
$event->setContents($contents);
}
}
});
@hissy

This comment has been minimized.

Copy link
Owner Author

commented Jan 1, 2019

Screenshot:

block_detail_tooltip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.