Semantic MediaWiki and related extensions
Register new datatype

This example shows how to register a new dataType/dataValue in Semantic MediaWiki and the convention for the datatype key is to use ___ as leading identifer to distinguish them from those defined by Semantic MediaWiki itself.

SMW::DataType::initTypes

use Hooks;
use Foo\DataValues\FooValue;
Hooks::register( 'SMW::DataType::initTypes', function ( $dataTypeRegistry ) {
$dataTypeRegistry->registerDatatype(
FooValue::TYPE_ID,
FooValue::class,
DataItem::TYPE_BLOB
);
$dataTypeRegistry->setOption(
'foovalue.SomeSetting',
42
);
return true;
};

DataValue representation

class FooValue extends DataValue {
const TYPE_ID = '___foo_bar';
protected function parseUserValue( $userValue ) {
...
}
}

Usage

$fooValue = DataValueFactory::getInstance()->newTypeIdValue(
'___foo_bar',
'Bar'
)
$fooValue->getShortWikiText();

About | General disclaimer | Privacy policy