documentation/Transformers/transformer-structure.md

39 lines
1.1 KiB
Markdown
Raw Normal View History

2023-11-22 21:57:19 +01:00
# Transformer Structure
2023-11-22 18:27:24 +01:00
To create a custom ActivityPub Transformer start by creating a class that extends the `\Activitypub\Transformer\Base` class and fill in all the required methods.
Each transformer needs to have a few basic settings — a unique name that will identify the transformer, a label that will be used as the title when being displayed in the settings section, and a list of supported post types that the transformer can use as an input.
2023-11-22 21:57:19 +01:00
## Transformer Class
2023-11-22 18:27:24 +01:00
First, we need to create a class that extends the `\Activitypub\Transformer\Base` class:
```php
class Acivitypub_Test_Transformer extends \Activitypub\Transformer\Base {
}
```
## Transformer Methods
A simple transformer skeleton class will look as follows:
```php
class Acivitypub_Test_Transformer extends \Activitypub\Transformer\Base {
public function get_name() {}
public function get_label() {}
public function get_object_type() {}
public function supported_post_types() {}
public function to_object() {}
// TODO
}
```
The `\Activitypub\Transformer\Base` class has many more methods, but the vast majority of your needs are covered by the methods mentioned above.
// TODO