diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2015-07-03 03:54:27 +0300 |
---|---|---|
committer | sgiehl <stefan@piwik.org> | 2015-10-06 18:25:13 +0300 |
commit | 9ba8f216fd7856ce5fef06bf82ecb8f8a2e7e630 (patch) | |
tree | 6ce07d18a85d00b39ab720abe042361c0775aead /plugins/ExamplePlugin | |
parent | 8ccc9dc05da021325cdbf141a548637fa52f16b2 (diff) |
generate pages instead of implementing them in each controller
Diffstat (limited to 'plugins/ExamplePlugin')
-rw-r--r-- | plugins/ExamplePlugin/Menu.php | 13 | ||||
-rw-r--r-- | plugins/ExamplePlugin/Widgets.php | 67 | ||||
-rw-r--r-- | plugins/ExamplePlugin/Widgets/MyExampleWidget.php | 80 |
3 files changed, 81 insertions, 79 deletions
diff --git a/plugins/ExamplePlugin/Menu.php b/plugins/ExamplePlugin/Menu.php index f890587fea..7c9acb90f6 100644 --- a/plugins/ExamplePlugin/Menu.php +++ b/plugins/ExamplePlugin/Menu.php @@ -9,27 +9,16 @@ namespace Piwik\Plugins\ExamplePlugin; use Piwik\Menu\MenuAdmin; -use Piwik\Menu\MenuReporting; use Piwik\Menu\MenuTop; use Piwik\Menu\MenuUser; /** * This class allows you to add, remove or rename menu items. - * To configure a menu (such as Admin Menu, Reporting Menu, User Menu...) simply call the corresponding methods as + * To configure a menu (such as Admin Menu, Top Menu, User Menu...) simply call the corresponding methods as * described in the API-Reference http://developer.piwik.org/api-reference/Piwik/Menu/MenuAbstract */ class Menu extends \Piwik\Plugin\Menu { - public function configureReportingMenu(MenuReporting $menu) - { - // reuse an existing category. Execute the showList() method within the controller when menu item was clicked - // $menu->addVisitorsItem('Report 1', $this->urlForAction('showList'), $orderId = 30); - // $menu->addActionsItem('Report 1', $this->urlForAction('showList'), $orderId = 30); - - // or create a custom category 'UI Framework' - // $menu->addItem('UI Framework', '', $this->urlForDefaultAction(), $orderId = 30); - // $menu->addItem('UI Framework', 'Report 1', $this->urlForAction('showList'), $orderId = 30); - } public function configureAdminMenu(MenuAdmin $menu) { diff --git a/plugins/ExamplePlugin/Widgets.php b/plugins/ExamplePlugin/Widgets.php deleted file mode 100644 index a5670902ef..0000000000 --- a/plugins/ExamplePlugin/Widgets.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - */ - -namespace Piwik\Plugins\ExamplePlugin; - -use Piwik\View; -use Piwik\WidgetsList; - -/** - * This class allows you to add your own widgets to the Piwik platform. In case you want to remove widgets from another - * plugin please have a look at the "configureWidgetsList()" method. - * To configure a widget simply call the corresponding methods as described in the API-Reference: - * http://developer.piwik.org/api-reference/Piwik/Plugin\Widgets - */ -class Widgets extends \Piwik\Plugin\Widgets -{ - /** - * Here you can define the category the widget belongs to. You can reuse any existing widget category or define - * your own category. - * @var string - */ - protected $category = 'Example Category'; - - /** - * Here you can add one or multiple widgets. You can add a widget by calling the method "addWidget()" and pass the - * name of the widget as well as a method name that should be called to render the widget. The method can be - * defined either directly here in this widget class or in the controller in case you want to reuse the same action - * for instance in the menu etc. - */ - protected function init() - { - // $this->addWidget('Example Widget Name', $method = 'myExampleWidget'); - // $this->addWidget('Example Widget 2', $method = 'myExampleWidget', $params = array('myparam' => 'myvalue')); - } - - /** - * This method renders a widget as defined in "init()". It's on you how to generate the content of the - * widget. As long as you return a string everything is fine. You can use for instance a "Piwik\View" to render a - * twig template. In such a case don't forget to create a twig template (eg. myViewTemplate.twig) in the - * "templates" directory of your plugin. - * - * @return string - */ - public function myExampleWidget() - { - // $view = new View('@ExamplePlugin/myViewTemplate'); - // return $view->render(); - - return 'My Widget Text'; - } - - /** - * Here you can remove any widgets defined by any plugin. - * - * @param WidgetsList $widgetsList - */ - public function configureWidgetsList(WidgetsList $widgetsList) - { - // $widgetsList->remove('NameOfWidgetCategory'); // will remove all widgets having this category - // $widgetsList->remove('NameOfWidgetCategory', 'Widget name'); // will only remove a specific widget - } -} diff --git a/plugins/ExamplePlugin/Widgets/MyExampleWidget.php b/plugins/ExamplePlugin/Widgets/MyExampleWidget.php new file mode 100644 index 0000000000..687ee6df67 --- /dev/null +++ b/plugins/ExamplePlugin/Widgets/MyExampleWidget.php @@ -0,0 +1,80 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\ExamplePlugin\Widgets; + +use Piwik\Widget\Widget; +use Piwik\Widget\WidgetConfig; +use Piwik\View; + +/** + * This class allows you to add your own widget to the Piwik platform. In case you want to remove widgets from another + * plugin please have a look at the "configureWidgetsList()" method. + * To configure a widget simply call the corresponding methods as described in the API-Reference: + * http://developer.piwik.org/api-reference/Piwik/Plugin\Widget + */ +class MyExampleWidget extends Widget +{ + public static function configure(WidgetConfig $config) + { + /** + * Set the category the widget belongs to. You can reuse any existing widget category or define + * your own category. + */ + $config->setCategoryId('Example Widgets'); + + /** + * Set the subcategory the widget belongs to. If a subcategory is set, the widget will be shown in the UI. + */ + // $config->setSubcategoryId('General_Overview'); + + /** + * Set the name of the widget belongs to. + */ + $config->setName('Example Widget Name'); + + /** + * Set the order of the widget. The lower the number, the earlier the widget will be listed within a category. + */ + $config->setOrder(99); + + /** + * Optionally set URL parameters that will be used when this widget is requested. + * $config->setParameters(array('myparam' => 'myvalue')); + */ + + /** + * Define whether a widget is enabled or not. For instance some widgets might not be available to every user or + * might depend on a setting (such as Ecommerce) of a site. In such a case you can perform any checks and then + * set `true` or `false`. If your widget is only available to users having super user access you can do the + * following: + * + * $config->setIsEnabled(\Piwik\Piwik::hasUserSuperUserAccess()); + * or + * if (!\Piwik\Piwik::hasUserSuperUserAccess()) + * $config->disable(); + */ + } + + /** + * This method renders the widget. It's on you how to generate the content of the widget. + * As long as you return a string everything is fine. You can use for instance a "Piwik\View" to render a + * twig template. In such a case don't forget to create a twig template (eg. myViewTemplate.twig) in the + * "templates" directory of your plugin. + * + * @return string + */ + public function render() + { + // $view = new View('@ExamplePlugin/myViewTemplate'); + // return $view->render(); + + return '<div>My Widget Text</div>'; + } + +}
\ No newline at end of file |