Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function render()
 {
     $build = array();
     $contexts = $this->getContexts();
     foreach ($this->getRegionAssignments() as $region => $blocks) {
         if (!$blocks) {
             continue;
         }
         $region_name = drupal_html_class("block-region-{$region}");
         $build[$region]['#prefix'] = '<div class="' . $region_name . '">';
         $build[$region]['#suffix'] = '</div>';
         /** @var $blocks \Drupal\block\BlockPluginInterface[] */
         foreach ($blocks as $block_id => $block) {
             if ($block instanceof ContextAwarePluginInterface) {
                 $this->contextHandler->preparePluginContext($block, $contexts);
             }
             if ($block->access($this->account)) {
                 $row = $block->build();
                 $block_name = drupal_html_class("block-{$block_id}");
                 $row['#prefix'] = '<div class="' . $block_name . '">';
                 $row['#suffix'] = '</div>';
                 $build[$region][$block_id] = $row;
             }
         }
     }
     return $build;
 }
 /**
  * @covers ::applyContextMapping
  *
  * @expectedException \Drupal\Component\Plugin\Exception\ContextException
  * @expectedExceptionMessage Assigned contexts were not satisfied: miss
  */
 public function testApplyContextMappingConfigurableAssignedMiss()
 {
     $context = $this->getMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
     $context->expects($this->never())->method('getContextValue');
     $contexts = array('name' => $context);
     $plugin = $this->getMock('Drupal\\Tests\\Core\\Plugin\\TestConfigurableContextAwarePluginInterface');
     $plugin->expects($this->once())->method('getContextDefinitions')->will($this->returnValue(array('hit' => 'hit')));
     $plugin->expects($this->never())->method('setContextValue');
     $this->contextHandler->applyContextMapping($plugin, $contexts, array('name' => 'miss'));
 }