Elgg\WidgetsService::validateType PHP Метод

validateType() публичный Метод

Checks if a widget type exists for a given id
См. также: elgg_is_widget_type
С версии: 1.9.0
public validateType ( string $id, string $context = null, ElggEntity $container = null )
$id string Widget identifier
$context string Optional context to check
$container ElggEntity Optional limit widget definitions to a container
    public function validateType($id, $context = null, \ElggEntity $container = null)
    {
        $types = $this->getTypes(['context' => $context, 'container' => $container]);
        $found = array_key_exists($id, $types);
        if (!$found && $context === null) {
            // Pre Elgg 2.2 this function returned true if a widget was registered regardless of context
            $found = array_key_exists($id, $this->widgets);
        }
        return $found;
    }

Usage Example

Пример #1
0
 /**
  * @depends testRegistrationParametersPreserveNameDescription
  * @param \Elgg\WidgetsService $service
  */
 public function testCanUnregisterType($service)
 {
     $this->assertTrue($service->unregisterType('widget_type'));
     $this->assertTrue($service->unregisterType('widget_type_con'));
     $this->assertTrue($service->unregisterType('widget_type_mul'));
     $this->assertTrue($service->unregisterType('widget_type_con_mul'));
     $this->assertFalse($service->unregisterType('widget_not_registered'));
     $this->assertFalse($service->validateType('widget_type'));
     $this->assertFalse($service->validateType('widget_type_con'));
     $this->assertFalse($service->validateType('widget_type_mul'));
     $this->assertFalse($service->validateType('not_registered_widget'));
 }