diff --git a/core/View/UIControl.php b/core/View/UIControl.php index 0590fe25529713228bc3018e49c2b4a894dd8d5f..111ef5813393e02e408865d1fa3089b9a00f6dbd 100644 --- a/core/View/UIControl.php +++ b/core/View/UIControl.php @@ -27,22 +27,6 @@ class UIControl extends \Piwik\View */ const TEMPLATE = ''; - /** - * Holds the array of values that are passed to the UIControl JavaScript class. - * - * @var array - */ - public $clientSideProperties = array(); - - /** - * Holds an array of values that are passed to the UIControl JavaScript class. These values - * differ from those in {@link $clientSideProperties} in that they are meant to passed as - * request parameters when the JavaScript code makes an AJAX request. - * - * @var array - */ - public $clientSideParameters = array(); - /** * The CSS class that is used to map the root element of this control with the JavaScript class. * @@ -86,9 +70,6 @@ class UIControl extends \Piwik\View $this->innerView = new View(static::TEMPLATE); parent::__construct("@CoreHome\_uiControl"); - - $this->clientSideProperties = array(); - $this->clientSideParameters = array(); } /** @@ -133,12 +114,54 @@ class UIControl extends \Piwik\View public function getTemplateVars($override = array()) { $this->templateVars['implView'] = $this->innerView; - $this->templateVars['clientSideProperties'] = $this->clientSideProperties; - $this->templateVars['clientSideParameters'] = $this->clientSideParameters; $this->templateVars['cssIdentifier'] = $this->cssIdentifier; $this->templateVars['cssClass'] = $this->cssClass; $this->templateVars['jsClass'] = $this->jsClass; + $this->templateVars['implOverride'] = $override; + + $innerTemplateVars = $this->innerView->getTemplateVars($override); + + $this->templateVars['clientSideProperties'] = array(); + foreach ($this->getClientSideProperties() as $name) { + $this->templateVars['clientSideProperties'][$name] = $innerTemplateVars[$name]; + } + + $this->templateVars['clientSideParameters'] = array(); + $clientSideParameters = $this->getClientSideParameters(); + foreach ($this->getClientSideParameters() as $name) { + $this->templateVars['clientSideParameters'][$name] = $innerTemplateVars[$name]; + } + + if ($this instanceof \Piwik\Plugins\SegmentEditor\SegmentSelectorControl) { + \Piwik\Log::warning(print_r($override, true)); + } return parent::getTemplateVars($override); } + + /** + * Returns the array of property names whose values are passed to the UIControl JavaScript class. + * + * Should be overriden by descendants. + * + * @return array + */ + public function getClientSideProperties() + { + return array(); + } + + /** + * Returns an array of property names whose values are passed to the UIControl JavaScript class. + * These values differ from those in {@link $clientSideProperties} in that they are meant to passed as + * request parameters when the JavaScript code makes an AJAX request. + * + * Should be overriden by descendants. + * + * @return array + */ + public function getClientSideParameters() + { + return array(); + } } \ No newline at end of file diff --git a/plugins/CoreHome/templates/_uiControl.twig b/plugins/CoreHome/templates/_uiControl.twig index f1d2343056b89adaf6ca862a1324333e05a3bf71..3f59b2c8a6c9ef2d37aa692aeda1632edda0ead3 100644 --- a/plugins/CoreHome/templates/_uiControl.twig +++ b/plugins/CoreHome/templates/_uiControl.twig @@ -1,6 +1,6 @@ <div class="{{ cssIdentifier }} {{ cssClass }}" data-props="{{ clientSideProperties|json_encode }}" data-params="{{ clientSideParameters|json_encode }}"> - {% render implView %} + {% render implView with implOverride %} </div> <script>$(document).ready(function () { require('piwik/UI').{{ jsClass }}.initElements(); });</script> \ No newline at end of file diff --git a/plugins/SegmentEditor/SegmentSelectorControl.php b/plugins/SegmentEditor/SegmentSelectorControl.php index 747bb6fdf5bd0b11cbb231d0b29162cb64c74d1e..80ac1735d74e57634707c9566b577eb85f9849a8 100644 --- a/plugins/SegmentEditor/SegmentSelectorControl.php +++ b/plugins/SegmentEditor/SegmentSelectorControl.php @@ -53,23 +53,29 @@ class SegmentSelectorControl extends UIControl $this->segmentsByCategory = $segmentsByCategory; $this->nameOfCurrentSegment = ''; - $this->clientSideProperties['isSegmentNotAppliedBecauseBrowserArchivingIsDisabled'] = 0; + $this->isSegmentNotAppliedBecauseBrowserArchivingIsDisabled = 0; - $savedSegments = API::getInstance()->getAll($this->idSite); - foreach ($savedSegments as &$savedSegment) { + $this->availableSegments = API::getInstance()->getAll($this->idSite); + foreach ($this->availableSegments as &$savedSegment) { $savedSegment['name'] = Common::sanitizeInputValue($savedSegment['name']); if (!empty($this->selectedSegment) && $this->selectedSegment == $savedSegment['definition']) { $this->nameOfCurrentSegment = $savedSegment['name']; - $this->clientSideProperties['isSegmentNotAppliedBecauseBrowserArchivingIsDisabled'] - = $this->wouldApplySegment($savedSegment) ? 0 : 1; + $this->isSegmentNotAppliedBecauseBrowserArchivingIsDisabled = + $this->wouldApplySegment($savedSegment) ? 0 : 1; } } - $this->clientSideProperties['availableSegments'] = $savedSegments; - $this->clientSideProperties['segmentTranslations'] = $this->getTranslations(); - $this->authorizedToCreateSegments = !Piwik::isUserIsAnonymous(); + $this->segmentTranslations = $this->getTranslations(); + } + + public function getClientSideProperties() + { + return array('availableSegments', + 'segmentTranslations', + 'isSegmentNotAppliedBecauseBrowserArchivingIsDisabled', + 'selectedSegment'); } private function wouldApplySegment($savedSegment)