protected function render_block(\blitze\sitemaker\model\blocks\entity\block $entity) { $block_name = $entity->get_name(); if ($block_instance = $this->block_factory->get_block($block_name)) { $default_settings = $block_instance->get_config(array()); $settings = $this->blocks->sync_settings($default_settings, $entity->get_settings()); $entity->set_settings($settings); $block_data = $entity->to_array(); $disp_data = $block_instance->display($block_data, true); return array_merge($block_data, array('id' => $block_data['bid'], 'title' => !empty($block_data['title']) ? $block_data['title'] : $this->user->lang($disp_data['title']), 'content' => !empty($disp_data['content']) ? $disp_data['content'] : $this->user->lang('BLOCK_NO_DATA'))); } }
/** * Render block * * @param array $display_modes * @param bool $edit_mode * @param array $data * @param array $users_groups * @param int $position_counter */ public function render(array $display_modes, $edit_mode, array $data, array $users_groups, &$position_counter) { $position = $data['position']; $service_name = $data['name']; if ($this->_block_is_viewable($data, $display_modes, $users_groups, $edit_mode) && ($block_instance = $this->block_factory->get_block($service_name)) !== null) { $block = $block_instance->display($data, $edit_mode); if ($content = $this->_get_block_content($block, $edit_mode)) { $tpl_data = array_merge($data, array('TITLE' => $this->_get_block_title($data['title'], $block['title']), 'CONTENT' => $content)); $this->template->assign_block_vars($position, array_change_key_case($tpl_data, CASE_UPPER)); $position_counter++; } } }
/** * @return array */ protected function _get_all_blocks() { $block_mapper = $this->mapper_factory->create('blocks', 'blocks'); $collection = $block_mapper->find(); $blocks = array(); foreach ($collection as $entity) { if ($block_instance = $this->block_factory->get_block($entity->get_name())) { $default_settings = $block_instance->get_config(array()); $settings = $this->sync_settings($default_settings, $entity->get_settings()); $entity->set_settings($settings); $style = $entity->get_style(); $route_id = $entity->get_route_id(); $position = $entity->get_position(); $blocks[$style][$route_id][$position][] = $entity; } } return $blocks; }
/** * Check if block exists * * @param string $service_name Service name of block * @return bool */ public function block_exists($service_name) { return $this->block_factory->get_block($service_name) ? true : false; }