Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
WidgetDefinition.php
Go to the documentation of this file.
1 <?php
2 namespace Elgg;
3 
11 
15  public $id;
16 
20  public $name;
21 
25  public $description;
26 
30  public $context;
31 
35  public $multiple;
36 
42  public function __construct($id) {
43  if (empty($id)) {
44  throw new \InvalidParameterException('Id missing for WidgetDefinition');
45  }
46 
47  $this->id = $id;
48  }
49 
64  public static function factory(array $options) {
65 
66  $id = elgg_extract('id', $options);
67  $definition = new WidgetDefinition($id);
68 
69  $name = elgg_extract('name', $options);
70  if (empty($name)) {
71  if (elgg_language_key_exists("widgets:{$id}:name")) {
72  $definition->name = elgg_echo("widgets:{$id}:name");
73  } elseif (elgg_language_key_exists($id)) {
74  $definition->name = elgg_echo($id);
75  } else {
76  $definition->name = $id;
77  }
78  } else {
79  $definition->name = $name;
80  }
81 
82  $description = elgg_extract('description', $options);
83  if (empty($description)) {
84  if (elgg_language_key_exists("widgets:{$id}:description")) {
85  $definition->description = elgg_echo("widgets:{$id}:description");
86  }
87  } else {
88  $definition->description = $description;
89  }
90 
91  $definition->context = (array) elgg_extract('context', $options, ['all']);
92  $definition->multiple = (bool) elgg_extract('multiple', $options, false);
93 
94  return $definition;
95  }
96 
104  public function __get($name) {
105  if ($name === 'handler') {
106  // before Elgg 2.2 the widget definitions had the handler attribute as the id
107  return $this->id;
108  }
109 
110  return $this->$name;
111  }
112 }
elgg_language_key_exists($key, $language= 'en')
Check if a given language key exists.
Definition: languages.php:133
__get($name)
Magic getter to return the deprecated attribute 'handler'.
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
$options
Elgg admin footer.
Definition: footer.php:6
if($categories) $description
Definition: full.php:166
static factory(array $options)
Create an WidgetDefinition from an associative array.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1310
WidgetDefinition.
if(!$collection_name) $id
Definition: add.php:17
__construct($id)
WidgetDefinition constructor.