Skip to content

Instantly share code, notes, and snippets.

@sdboyer
Created June 18, 2013 20:19
Show Gist options
  • Select an option

  • Save sdboyer/5808962 to your computer and use it in GitHub Desktop.

Select an option

Save sdboyer/5808962 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Contains \Drupal\menu\Plugin\Block\MenuBlock.
*/
namespace Drupal\menu\Plugin\Block;
use Drupal\system\Plugin\Block\SystemMenuBlock;
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Provides a generic Menu block.
*
* @Plugin(
* id = "menu_menu_block",
* admin_label = @Translation("Menu"),
* module = "menu",
* derivative = "Drupal\menu\Plugin\Derivative\MenuBlock"
* )
*/
class MenuBlock extends SystemMenuBlock {
/**
* {@inheritdoc}
*/
public function build() {
list($plugin, $menu) = explode(':', $this->getPluginId());
// @todo i dunno the exactness of this part, esp. if we want the context to be 'optional'
$url = $this->getContext('url thinger');
if ($url) {
// Force the menu tree renderer to use the custom path.
menu_tree_set_path($menu, $url->getContextValue());
}
$ret = menu_tree($menu);
if ($url) {
// Undo the damage.
$paths = drupal_static('menu_tree_set_path');
unset($paths[$menu]);
}
return $ret;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment