/** * Makes a new plugin setting available. * * @param Setting $setting * @throws \Exception If there is a setting with the same name that already exists. * If the name contains non-alphanumeric characters. */ protected function addSetting(Setting $setting) { $name = $setting->getName(); if (!ctype_alnum($name)) { $msg = sprintf('The setting name "%s" in plugin "%s" is not valid. Only alpha and numerical characters are allowed', $setting->getName(), $this->pluginName); throw new \Exception($msg); } if (array_key_exists($name, $this->settings)) { throw new \Exception(sprintf('A setting with name "%s" does already exist for plugin "%s"', $setting->getName(), $this->pluginName)); } $this->setDefaultTypeAndFieldIfNeeded($setting); $this->addValidatorIfNeeded($setting); $setting->setStorage($this->storage); $setting->setPluginName($this->pluginName); $this->settings[$name] = $setting; }
/** * @param $setting * @throws \Exception */ private function checkHasEnoughReadPermission(Setting $setting) { // When the request is a Tracker request, allow plugins to read settings if (SettingsServer::isTrackerApiRequest()) { return; } if (!$setting->isReadableByCurrentUser()) { $errorMsg = Piwik::translate('CoreAdminHome_PluginSettingReadNotAllowed', array($setting->getName(), $this->pluginName)); throw new \Exception($errorMsg); } }
private function formatMetadata(Setting $setting) { $config = $setting->configureField(); $availableValues = $config->availableValues; if (is_array($availableValues)) { $availableValues = (object) $availableValues; } return array('name' => $setting->getName(), 'title' => $config->title, 'value' => $setting->getValue(), 'defaultValue' => $setting->getDefaultValue(), 'type' => $setting->getType(), 'uiControl' => $config->uiControl, 'uiControlAttributes' => $config->uiControlAttributes, 'availableValues' => $availableValues, 'description' => $config->description, 'inlineHelp' => $config->inlineHelp, 'introduction' => $config->introduction, 'condition' => $config->condition); }
public function setValue(Setting $setting, $value) { $this->toBeDeleted[$setting->getName()] = false; // prevent from deleting this setting, we will create/update it parent::setValue($setting, $value); }
/** * @param $setting * @throws \Exception */ private function checkHasEnoughPermission(Setting $setting) { if (!$setting->canBeDisplayedForCurrentUser()) { $errorMsg = Piwik::translate('CoreAdminHome_PluginSettingChangeNotAllowed', array($setting->getName(), $this->pluginName)); throw new \Exception($errorMsg); } }