Elgg  Version 6.1
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()->events->triggerResults('plugin_setting', $this->getType(), [
23  'entity' => $this,
24  'plugin_id' => $plugin_id,
25  'name' => $name,
26  'value' => $value,
27  ], $value);
28 
29  $name = $this->getNamespacedPluginSettingName($plugin_id, $name);
30 
31  return elgg_call(ELGG_DISABLE_SYSTEM_LOG, function() use ($name, $value) {
32  return $this->setMetadata($name, $value);
33  });
34  }
35 
45  public function getPluginSetting(string $plugin_id, string $name, $default = null) {
46  $name = $this->getNamespacedPluginSettingName($plugin_id, $name);
47 
48  return $this->getMetadata($name) ?? $default;
49  }
50 
59  public function removePluginSetting(string $plugin_id, string $name): bool {
60  $name = $this->getNamespacedPluginSettingName($plugin_id, $name);
61 
62  return elgg_call(ELGG_DISABLE_SYSTEM_LOG, function() use ($name) {
63  return $this->deleteMetadata($name);
64  });
65  }
66 
75  final public function getNamespacedPluginSettingName(string $plugin_id, string $name): string {
76  return "plugin:{$this->getType()}_setting:{$plugin_id}:{$name}";
77  }
78 }
$default
Definition: checkbox.php:30
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
Definition: elgglib.php:306
const ELGG_DISABLE_SYSTEM_LOG
Definition: constants.php:125
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
deleteMetadata(string $name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
Definition: Metadata.php:198
$plugin_id
Remove all user and plugin settings from the give plugin ID.
Definition: remove.php:8
$value
Definition: generic.php:51
setMetadata(string $name, mixed $value, string $value_type= '', bool $multiple=false)
Set metadata on this entity.
Definition: Metadata.php:78
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
getMetadata(string $name)
Return the value of a piece of metadata.
Definition: Metadata.php:27