Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Widgets API for plugins #7927

Merged
merged 12 commits into from May 19, 2015
Merged

Change Widgets API for plugins #7927

merged 12 commits into from May 19, 2015

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented May 18, 2015

refs #7861

This is a PR just to collect feedback. Please don't merge for now. It's a bit hard to explain for now but it'll make more sense after also having more code in #7822

For more information see #7861

This code will be used in Piwik 3.0. We don't need to care about BC but this code is BC for now.

Now a widget will be basically configured like this:

class GetVisitorProfilePopup extends \Piwik\Plugin\Widget
{
    public static function configure(WidgetConfig $config)
    {
        $config->setCategory('Live!');
        $config->setName('Live_VisitorProfile');
        $config->setOrder(25);
        $config->disable();
    }

    public function render()
    {
    }

    public static function configureWidgetsList(WidgetsList $widgetsList)
    {
        // only needed in rare cases when removing a widget or so
    }

}

WidgetConfig can be also used in a WidgetsList.addWidgets event (although this is currently deprecated)

$config = new WidgetConfig();
$config->setCategory('Live!');
$config->setName(Piwik::translate('UserCountryMap_RealTimeMap'));
$config->setModule('UserCountryMap');
$config->setAction('realtimeMap');
$config->setOrder(5);
WidgetsList::getInstance()->addWidget($config);

// instead of 
WidgetsList::add('Live!', Piwik::translate('UserCountryMap_RealTimeMap'), 'UserCountryMap', 'realtimeMap', array(), $order = 5);

And it will be probably used in reports to create a widget from a report eg

    protected function init()
    {
        parent::init();
        $this->order = 2;

        $this->createWidget()
             ->setName('Live_VisitorLog')
             ->setOrder(10)
             ->setParameters(array('small' => 1));
    }

@tsteur tsteur added the Needs Review PRs that need a code review label May 18, 2015
@tsteur tsteur added this to the 2.14.0 milestone May 18, 2015
@@ -341,21 +348,69 @@ public function render()
return $rendered;
}

protected function createWidget()
{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't care about code in this class for now. This will be completely changed in #7822

@mattab mattab added the Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. label May 19, 2015
@tsteur tsteur merged commit d848ff9 into 7822_2 May 19, 2015
@tsteur
Copy link
Member Author

tsteur commented May 19, 2015

Merged it into that branch for now as I need it there and noticed I can remove a couple of things afterwards. Eg the static method configureWidgetsList from all widget classes.

@mnapoli mnapoli deleted the 7861_2 branch May 26, 2015 12:55
@mattab mattab added the not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. label Jun 24, 2015
@mattab mattab modified the milestones: 3.0.0-b1, 2.14.0 Oct 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants