Elgg  Version 4.3
PluginSettings.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Traits\Entity;
4 
10 trait PluginSettings {
11 
21  public function setPluginSetting(string $plugin_id, string $name, $value): bool {
22  $value = _elgg_services()->hooks->trigger('plugin_setting', $this->getType(), [
23  'entity' => $this,
24  'plugin_id' => $plugin_id,
25  'name' => $name,
26  'value' => $value,
27  ], $value);
28 
29  if (isset($value) && !is_scalar($value)) {
30  elgg_log("Invalid value type provided to save plugin setting '{$name}' for plugin '{$plugin_id}' only scalars are allowed", 'ERROR');
31  return false;
32  }
33 
34  $name = $this->getNamespacedPluginSettingName($plugin_id, $name);
35 
36  return $this->setPrivateSetting($name, $value);
37  }
38 
48  public function getPluginSetting(string $plugin_id, string $name, $default = null): string {
49  $name = $this->getNamespacedPluginSettingName($plugin_id, $name);
50 
51  return (string) ($this->getPrivateSetting($name) ?? $default);
52  }
53 
62  public function removePluginSetting(string $plugin_id, string $name): bool {
63  $name = $this->getNamespacedPluginSettingName($plugin_id, $name);
64 
65  return $this->removePrivateSetting($name);
66  }
67 
76  final public function getNamespacedPluginSettingName(string $plugin_id, string $name): string {
77  return "plugin:{$this->getType()}_setting:{$plugin_id}:{$name}";
78  }
79 }
$default
Definition: checkbox.php:31
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
$plugin_id
Remove all user and plugin settings from the give plugin ID.
Definition: remove.php:8
$value
Definition: generic.php:51
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:399
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638