Elgg\WidgetsService::getTypes PHP Method

getTypes() public method

Since: 1.9.0
public getTypes ( array $params = [] ) : WidgetDefinition[]
$params array Associative array of params used to determine what to return array ( 'context' => string (defaults to elgg_get_context()), 'container' => \ElggEntity (defaults to null) )
return WidgetDefinition[]
    public function getTypes(array $params = [])
    {
        $context = elgg_extract('context', $params, '');
        if (!$context) {
            $context = elgg_get_context();
            $params['context'] = $context;
        }
        $available_widgets = _elgg_services()->hooks->trigger('handlers', 'widgets', $params, $this->widgets);
        if (!is_array($available_widgets)) {
            return [];
        }
        $widgets = [];
        foreach ($available_widgets as $widget_definition) {
            if (!$widget_definition instanceof WidgetDefinition) {
                continue;
            }
            if (in_array($context, $widget_definition->context)) {
                $widgets[$widget_definition->id] = $widget_definition;
            }
        }
        return $widgets;
    }

Usage Example

Beispiel #1
0
 /**
  * @depends testRegistrationParametersPreserveMultiple
  * @param \Elgg\WidgetsService $service
  */
 public function testRegistrationParametersPreserveNameDescription($service)
 {
     $resps = array('widget_type' => array('Widget name1', 'Widget description1'), 'widget_type_con' => array('Widget name2', 'Widget description2'), 'widget_type_mul' => array('Widget name3', 'Widget description3'), 'widget_type_con_mul' => array('Widget name5', 'Widget description5'));
     $contexts = array('dashboard', 'profile', 'settings');
     foreach ($contexts as $context) {
         $items = $service->getTypes(['context' => $context]);
         foreach ($items as $id => $item) {
             $this->assertInstanceOf('\\Elgg\\WidgetDefinition', $item);
             $this->assertNotEmpty($id);
             $this->assertInternalType('string', $id);
             $this->assertArrayHasKey($id, $resps);
             list($name, $desc) = $resps[$id];
             $this->assertSame($name, $item->name);
             $this->assertSame($desc, $item->description);
         }
     }
     return $service;
 }
All Usage Examples Of Elgg\WidgetsService::getTypes