XenForo 2 add-on development reference

Here is a short reference of some points in source code, which should help you to create XenForo 2 add-on. At first, I recommend you follow the official tutorial with an add-on sample.
You can find it here:
https://xenforo.com/xf2-docs/dev/lets-build-an-add-on/
Below you will find additional information I discovered during writing my add-on.

Prepare environment

FROM php:7.2-apache

RUN apt-get update \
&& apt-get install -y \
zip \
zlib1g-dev \
libz-dev \
libmemcached-dev \
libpng-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libgd-dev

RUN a2enmod rewrite \
&& pecl install memcache xdebug-2.6.1 \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd mysqli zip \
&& docker-php-ext-enable memcache xdebug \
&& echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini

And the content of docker-compose.yml file:

version: '3'

services:
php:
build: ./docker/php #path to
container_name: php_container
environment:
XDEBUG_CONFIG: "remote_host=172.17.0.1 remote_port=9000"
PHP_IDE_CONFIG: serverName=localhost
volumes:
- ./app:/var/www/html
ports:
- 80:80

mariadb:
image: mariadb:10.4
environment:
MYSQL_ROOT_PASSWORD: pass
MYSQL_DATABASE: database_name
volumes:
- db:/var/lib/mysql
ports:
- 3306:3306

memcache:
image: memcached:alpine
ports:
- 11211:11211

volumes:
db:

XenForo 2 console commands

docker exec -it -u www-data php_container bash

Then you can list all commands and filter them:

$ php cmd.php | grep addon

Add-on commands located in src/XF/Cli/Command/AddOn folder.

Add-on data

Setup script

Extend entity

Event listeners

Use composer packages

Template functions

Originally published at https://bogomolov.tech.

Web Developer | PHP Certified | Digital Nomad