Elgg  Version master
WidgetDefinition.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg;
4 
6 
12 #[\AllowDynamicProperties]
14 
18  public $id;
19 
23  public $name;
24 
28  public $description;
29 
33  public $context;
34 
38  public $multiple;
39 
44 
52  public function __construct($id) {
53  if (empty($id)) {
54  throw new InvalidArgumentException('"id" missing for ' . __CLASS__);
55  }
56 
57  $this->id = $id;
58  }
59 
72  public static function factory(array $options) {
73 
74  $id = (string) elgg_extract('id', $options);
75  $definition = new WidgetDefinition($id);
76 
77  $name = elgg_extract('name', $options);
78  if (empty($name)) {
79  if (elgg_language_key_exists("widgets:{$id}:name")) {
80  $definition->name = elgg_echo("widgets:{$id}:name");
82  $definition->name = elgg_echo($id);
83  } else {
84  $definition->name = $id;
85  }
86  } else {
87  $definition->name = $name;
88  }
89 
90  $description = elgg_extract('description', $options);
91  if (empty($description)) {
92  if (elgg_language_key_exists("widgets:{$id}:description")) {
93  $definition->description = elgg_echo("widgets:{$id}:description");
94  }
95  } else {
96  $definition->description = $description;
97  }
98 
99  $context = (array) elgg_extract('context', $options, ['profile', 'dashboard']);
100  $definition->context = $context;
101 
102  $definition->multiple = (bool) elgg_extract('multiple', $options, false);
103 
104  $definition->required_plugin = (array) elgg_extract('required_plugin', $options, []);
105 
106  return $definition;
107  }
108 
114  public function isValid() {
115  return $this->checkRequiredActivePlugins();
116  }
117 
123  protected function checkRequiredActivePlugins() {
124  if (empty($this->required_plugin)) {
125  return true;
126  }
127 
128  foreach ($this->required_plugin as $plugin) {
129  if (!elgg_is_active_plugin($plugin)) {
130  return false;
131  }
132  }
133 
134  return true;
135  }
136 }
$plugin
$context
Definition: add.php:8
Exception thrown if an argument is not of the expected type.
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
isValid()
Checks if the widget definition meets all requirements.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
checkRequiredActivePlugins()
Checks if the required plugins are active.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
elgg_language_key_exists(string $key, string $language= 'en')
Check if a given language key exists.
Definition: languages.php:44
static factory(array $options)
Create an WidgetDefinition from an associative array.
elgg_is_active_plugin(string $plugin_id)
Returns if a plugin is active for a current site.
Definition: plugins.php:27
$description
Definition: record.php:15
WidgetDefinition.
$id
Generic annotation delete action.
Definition: delete.php:6
__construct($id)
WidgetDefinition constructor.