public function action_location() { $id = $this->request->param('id'); $widget = ORM::factory('widget', $id); if (!$widget->loaded()) { Messages::errors(__('Widget not found!')); $this->go_back(); } // check if trying to save if (Request::current()->method() == Request::POST) { return $this->_add_location($widget); } $this->template->title = __('Widget :name location', array(':name' => $widget->name)); $this->breadcrumbs->add(__('Widget :name', array(':name' => $widget->name)), Route::get('backend')->uri(array('controller' => 'widgets', 'action' => 'edit', 'id' => $widget->id)))->add(__('Widget location')); list($page_widgets, $pages_widgets) = $widget->locations(); $pages = Model_Page_Sitemap::get(TRUE)->as_array(); $this->template->content = View::factory('widgets/location', array('widget' => $widget, 'pages' => $pages, 'page_widgets' => $page_widgets, 'pages_widgets' => $pages_widgets, 'layouts_blocks' => Widget_Manager::get_blocks_by_layout())); }
Block::run('PRE'); }); Observer::observe('frontpage_after_render', function () { /** * Запуск метода в виджетах текущей страницы * Model_Widget_Decorator::after_page_load */ Observer::notify('after_page_load'); /** * Блок служит для помещения в него виджета с произволным PHP кодом, * который выполняется после загрузки HTML */ Block::run('POST'); }); Observer::observe('view_page_edit_plugins', function ($page) { $blocks = Widget_Manager::get_blocks_by_layout($page->layout()); echo View::factory('widgets/page/edit', array('page' => $page, 'pages' => Model_Page_Sitemap::get(TRUE)->exclude(array($page->id))->flatten(), 'widgets' => Widget_Manager::get_widgets_by_page($page->id), 'blocks' => Arr::get($blocks, $page->layout()))); }); Observer::observe('page_add_after_save', function ($page) { $post_data = Request::current()->post('widgets'); if (!empty($post_data['from_page_id'])) { Widget_Manager::copy($post_data['from_page_id'], $page->id); } }); Observer::observe('page_edit_after_save', function ($page) { $post_data = Request::current()->post('widget'); if (!is_array($post_data)) { return; } foreach ($post_data as $widget_id => $block) { Widget_Manager::update_location_by_page($page->id, $widget_id, $block);
public function get_blocks() { $layout_name = $this->param('layout', NULL); $blocks = Widget_Manager::get_blocks_by_layout($layout_name); $this->response($blocks); }