18 protected array $temp_metadata = [];
39 return array_map(
function($values) {
40 return count($values) > 1 ? $values : $values[0];
41 }, $this->temp_metadata);
45 if ($metadata === null) {
49 if (empty($metadata)) {
53 $metadata_values = [];
54 foreach ($metadata as $md) {
55 $metadata_values[$md->name][] = $md->value;
58 return array_map(
function($values) {
59 return count($values) > 1 ? $values : $values[0];
79 if ($value === null || $value ===
'' || $value === []) {
85 if (is_array($value)) {
86 $value = array_values(array_filter($value,
function($var) {
88 return !is_null($var) && $var !==
'';
94 if (
count($value) === 0) {
98 if (empty($this->guid)) {
106 $md_cache_enabled = $md_cache->isEnabled();
107 $md_cache->disable();
108 $restore_md_cache =
function() use ($md_cache, $md_cache_enabled) {
109 if ($md_cache_enabled) {
116 $existing_ids =
_elgg_services()->metadataTable->getIDsByName($this->guid, $name);
118 if ((is_array($existing_ids) ||
count($value) > 1) && isset($existing_ids)) {
128 if (
count($value) > 1) {
134 foreach ($value as $value_tmp) {
140 if (!empty($value_type)) {
169 unset($this->temp_metadata[$name]);
178 if (!isset($this->temp_metadata[$name])) {
179 $this->temp_metadata[
$name] = [];
182 $this->temp_metadata[
$name] = array_merge($this->temp_metadata[$name], $value);
202 if (isset($this->temp_metadata[
$name])) {
203 unset($this->temp_metadata[$name]);
206 $this->temp_metadata = [];
213 'guid' => $this->guid,
215 'metadata_name' =>
$name,
if(!$user||!$user->canDelete()) $name
deleteMetadata(string $name=null)
Deletes all metadata on this object (metadata.entity_guid = $this->guid).
getAllMetadata()
Get all entity metadata.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
setTempMetadata(string $name, mixed $value, bool $multiple=false)
Set temp metadata on this entity.
setMetadata(string $name, mixed $value, string $value_type= '', bool $multiple=false)
Set metadata on this entity.
_elgg_services()
Get the global service provider.
getMetadata(string $name)
Return the value of a piece of metadata.
$guid
Reset an ElggUpgrade.