Skip to content

A starter template for quickly creating new Moodle plugins with pre-configured tooling for development, testing, and code quality.

License

Notifications You must be signed in to change notification settings

Frezzu/create-moodle-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moodle Plugin Starter

A starter template for quickly creating new Moodle plugins with pre-configured tooling for development, testing, and code quality.

Features

  • 🚀 Quick Setup - Create a new plugin in seconds
  • 🐳 Docker Integration - Pre-configured moodle-docker setup
  • Code Formatting - PHP-CS-Fixer with Moodle coding standards
  • 🧪 Testing - PHPUnit and Behat ready to go
  • 📦 Composer Scripts - Convenient commands for common tasks

Quick Start

Create a New Plugin

composer create-project frezzu/create-moodle-plugin moodle-local_my_plugin

The folder name format is [moodle-]<type>_<name>:

  • moodle-local_my_plugin → Plugin type: local, name: my_plugin
  • mod_quiz_extra → Plugin type: mod, name: quiz_extra
  • block_dashboard → Plugin type: block, name: dashboard

The moodle- prefix is optional.

Supported Plugin Types

Common types: local, mod, block, theme, tool, report, auth, enrol, format, filter

Development Setup

Prerequisites

  1. moodle-docker: Clone https://github.com/moodlehq/moodle-docker/ and add to PATH:

    git clone https://github.com/moodlehq/moodle-docker.git ~/tools/moodle-docker
    export PATH="$PATH:$HOME/tools/moodle-docker/bin"
  2. Composer: Ensure you have Composer installed.

Initialize Environment

After creating your plugin:

# Install dependencies
composer install

# Setup moodle-docker
composer setup

# Start containers
composer compose-up

# Initialize database (first time only)
composer db-init

Access Moodle at http://localhost:8000

  • Username: admin
  • Password: test

Access Adminer (database UI) at http://localhost:8082

Available Commands

Docker Management

composer compose-up      # Start containers
composer compose-down    # Stop containers
composer db-init         # Initialize database

Testing

# PHPUnit
composer test-php-init   # Initialize PHPUnit (once)
composer test-php        # Run PHPUnit tests
composer test-php-drop   # Drop PHPUnit database

# Behat
composer test-behat-init # Initialize Behat (once)
composer test-behat      # Run Behat tests
composer test-behat-drop # Drop Behat database

Code Quality

composer fix             # Fix code style issues
composer fix-dry         # Check code style (dry run)

Project Structure

your-plugin/
├── .moodle/              # Moodle core (ignored by git)
├── bin/
│   └── setup.sh          # Setup script
├── classes/              # Plugin classes
├── db/                   # Database definitions
├── lang/
│   └── en/
│       └── *.php         # Language strings
├── tests/                # PHPUnit and Behat tests
├── .php-cs-fixer.php     # Code style config
├── composer.json         # Dependencies and scripts
└── version.php           # Plugin metadata

VS Code Integration

The starter includes VS Code settings for automatic code formatting with PHP-CS-Fixer. Install the extension:

License

GPL-3.0-or-later

About

A starter template for quickly creating new Moodle plugins with pre-configured tooling for development, testing, and code quality.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published