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

Add OptOut hook #7979

Closed
wants to merge 1 commit into from
Closed

Add OptOut hook #7979

wants to merge 1 commit into from

Conversation

Zeichen32
Copy link
Contributor

In relation to issue #7962

  • Add a event to optout controller to allow plugins to change the optout template.
  • Add Twig Blocks in optout template, to allow plugins to extend the optout template.

@tsteur
Copy link
Member

tsteur commented May 24, 2015

Would it be possible to listen to the Controller events instead? See http://developer.piwik.org/api-reference/events#controller . This would allow you to extend or replace the content of the optOutView. You could listen to Controller.CoreAdminHome.optOutView.end in your plugin. $result will contain the rendered HTML of that action and you can extend or replace it.

@Zeichen32
Copy link
Contributor Author

Sure but then I have to parse the rendered HTML to add some css. I think its a much better way to change the view object and extends the twig template.

@tsteur
Copy link
Member

tsteur commented May 25, 2015

I totally understand that. Problem is that needs are so differently, we'd probably end up adding an event in each action at some point. That's why we introduced those generic ones. Also understand re the view.

One problem I see here is that we don't have a "process" for keeping backwards compatibility for templates. We do not see templates as a public API so far (and I doubt it will change since we want to render everything in the browser anyway). Meaning it would be easily possible that at some point someone will remove those twig blocks and your custom opt out would no longer work.

If we do here something, I'd rather post an event in the template directly similar to https://github.com/piwik/piwik/blob/2.14.0-b1/plugins/CoreHome/templates/_topBar.twig#L1 . This way at least everyone would be aware that there is something we should to keep BC. Still, we usually don't add those events directly in the template and try to avoid them. They will be also not documented and it could still happen that we remove them.

Do you need all three blocks? They basically cover the whole page to be replaced?

@Zeichen32
Copy link
Contributor Author

I need just one twig block in the head section and a event in the controller action to inject the custom css style. I can change my commit and remove the other twig blocks.

@mattab
Copy link
Member

mattab commented Jun 24, 2015

I totally understand that. Problem is that needs are so differently, we'd probably end up adding an event in each action at some point. That's why we introduced those generic ones. Also understand re the view.

@tsteur maybe we could add a new generic event in View->render(), that would pass the View object as parameter?

@tsteur
Copy link
Member

tsteur commented Jun 24, 2015

That would be possible but maybe a bit fragile? Eg the template name might change over time when doing Piwik::postEvent('View.render', array(View $view=$this, $this->templateFile)). The template file names would become API.

I'm not really sure of the benefit as one cannot change the templateFile after the view was created from what I know. Meaning one could only change some view variables? Unless we pass $view by reference and let developers completely replace the view instance but this might not be really practical since one has to copy all template vars and set them again apart from the once one want to change.

As template names become API I would not really want to do that.

@Zeichen32
Copy link
Contributor Author

Another way could be to create a OptOutManager which include the whole optout logic. This manager could be trigger some events to extends / replace the OptOut logic and finally return the view object.

Currently the CoreAdminHome controller includes some optout logic, that may be better placed in a seperate manager / service.

@tsteur
Copy link
Member

tsteur commented Jun 24, 2015

I agree the OptOut can be quite an important part for someone that uses Piwik as it is visible on the website etc. It would be nice to be able to make some more tweaks. I'd prefer not letting users change the view or templates but provide specific API's to change behaviour or look. The look could be eg changed with additional custom CSS files, we could users allow to add JS files to the header as well. We could also add some disable/enable options. This wouldn't be via Twig or View but via a method that can be called on the OptOutManager. I presume this is what you meant 👍

I presume it shouldn't be too much work to do such things. Class could be like

class OptOutManager {

function addJsFile($path);
function addCssFile($path);
function setTitle($title); // (overwrites default title)
function enable/disableShowConfirmOnly();
}

@Zeichen32
Copy link
Contributor Author

I agree that it shouldn't be much work to create this OptOutManager. If it is ok for you, i can work on it and create new pr.

@tsteur
Copy link
Member

tsteur commented Jun 25, 2015

👍 that would be very much appreciated and for sure many users would benefit from it

@Zeichen32 Zeichen32 mentioned this pull request Jun 26, 2015
3 tasks
@Zeichen32
Copy link
Contributor Author

I close this PR in favor of PR #8229

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants