Last active
January 2, 2019 07:57
-
-
Save hissy/db61cce359f13deed0d60d9b72fc7778 to your computer and use it in GitHub Desktop.
[concrete5] [Debug tool] Tooltip to display block detail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screenshot: