simpleteam/craft-toolkit

A comprehensive toolkit for Craft CMS - provides options, utilities, and enhanced functionality

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:craft-plugin

pkg:composer/simpleteam/craft-toolkit

0.9.2 2025-09-09 02:41 UTC

This package is auto-updated.

Last update: 2026-01-09 03:27:20 UTC


README

A comprehensive toolkit for Craft CMS that provides complementary functionality and utilities. Currently includes an options system for easy key-value storage accessible via Craft::$app->options.

Installation

composer require simpleteam/craft-toolkit
# Activation on DDEV
ddev craft plugin/install simpleteam-craft-toolkit

The plugin will automatically register the options component when installed.

Usage

Once installed, you can use the options component anywhere in your Craft application:

Store a value

Craft::$app->options->set('my_key', 'my_value');

// Store complex data (automatically will be JSON encoded)
Craft::$app->options->set('user_preferences', [
    'theme' => 'dark',
    'language' => 'en',
    'notifications' => true
]);

Retrieve a value

$value = Craft::$app->options->get('my_key');

// With default value
$theme = Craft::$app->options->get('my_key', 'some_default_value');

Check if option exists

if (Craft::$app->options->exists('my_key')) {
    // Option exists
}

// Or use the alias
if (Craft::$app->options->has('my_key')) {
    // Option exists
}

Delete an option

Craft::$app->options->delete('my_key');

Get all options

$allOptions = Craft::$app->options->getAll();

// Get only autoload options
$autoloadOptions = Craft::$app->options->getAll(true);

Set multiple options

Craft::$app->options->setMultiple([
    'option1' => 'value1',
    'option2' => 'value2',
    'option3' => ['complex' => 'data']
]);

Features

Options System

  • Automatic Installation: No manual configuration required
  • WordPress-like API: Familiar interface for WordPress developers
  • JSON Support: Automatically handles complex data types
  • Database Storage: Uses a dedicated table with proper indexing
  • Autoload Support: Option to mark frequently used options for caching
  • Clean Syntax: Available anywhere via Craft::$app->options

Database

The plugin automatically creates a simple_options table with the following structure:

  • id - Primary key
  • key - Option key (unique index)
  • value - Option value (longtext)
  • isJson - Boolean flag for JSON data
  • autoload - Boolean flag for autoloading
  • dateCreated - Creation timestamp
  • dateUpdated - Last update timestamp

Requirements

  • Craft CMS 5.0 or later
  • PHP 8.0 or later

License

MIT License