BasePlugin

Type
Abstract Class
Namespace
Craft
Inherits
Craft\BasePlugin » Craft\BaseSavableComponentType » Craft\BaseComponentType » Craft\BaseApplicationComponent » CApplicationComponent » CComponent
Implements
Craft\IComponentType, Craft\IPlugin, Craft\ISavableComponentType, IApplicationComponent
Since
1.0

Plugin base class.

See also http://craftcms.com

View source

Public Properties

PropertyDescription
$behaviorsarray – The behaviors that should be attached to this component.
$isEnabledboolean
$isInstalledboolean
$modelCraft\BaseModel

$isEnabled

Signature

public boolean $isEnabled = false

$isInstalled

Signature

public boolean $isInstalled = false

Protected Properties

PropertyDescription
$componentTypestring

$componentType

Signature

protected string $componentType = 'Plugin'

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__get()Returns a property value, an event handler list or a behavior based on its name.
__isset()Checks if a property value is null.
__set()Sets value of a component property.
__unset()Sets a component property to be null.
asa()Returns the named behavior object.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
attachEventHandler()Attaches an event handler to an event.
canGetProperty()Determines whether a property can be read.
canSetProperty()Determines whether a property can be set.
createTables()Creates any tables defined by the plugin’s records.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
detachEventHandler()Detaches an existing event handler.
disableBehavior()Disables an attached behavior.
disableBehaviors()Disables all behaviors attached to this component.
dropTables()Drops any tables defined by the plugin’s records.
enableBehavior()Enables an attached behavior.
enableBehaviors()Enables all behaviors attached to this component.
evaluateExpression()Evaluates a PHP expression or callback under the context of this component.
getClassHandle()Returns the component’s handle, ideally based on the class name.
getDescription()Returns the plugin’s description.
getDeveloper()Returns the plugin developer’s name.
getDeveloperUrl()Returns the plugin developer’s URL.
getDocumentationUrl()Returns the plugin documentation’s URL.
getEventHandlers()Returns the list of attached event handlers for an event.
getIsInitialized()Checks if this application component has been initialized.
getName()Returns the component’s name.
getRecords()Returns the record classes provided by this plugin.
getReleaseFeedUrl()Returns the plugin’s releases JSON feed URL.
getSchemaVersion()Returns the plugin’s schema version number.
getSettings()Returns the component’s settings model.
getSettingsHtml()Returns the component’s settings HTML.
getSettingsUrl()Returns the URL to the plugin’s settings page in the CP.
getSourceLanguage()Returns the locale ID that identifies what language the plugin was written in.
getVersion()Returns the plugin’s version number.
hasCpSection()Returns whether this plugin has its own section in the CP.
hasEvent()Determines whether an event is defined.
hasEventHandler()Checks whether the named event has attached handlers.
hasProperty()Determines whether a property is defined.
hasSettings()Returns whether the plugin has settings.
init()Initializes the application component.
isInitialized()Checks if this application component has been initialized yet, or not.
isSelectable()Returns whether this component should be shown when the user is creating a component of this type.
log()A wrapper for writing to the log files for plugins that will ultimately call {@link Craft::log()}. This allows plugins to be able to write to their own log files at craft/storage/runtime/logs/pluginHandle.log using PluginHandle::log() syntax.
onAfterInstall()Performs any actions that should occur after the plugin is installed.
onBeforeInstall()Performs any actions that should occur before the plugin is installed.
onBeforeUninstall()Performs any actions that should occur before the plugin is uninstalled.
prepSettings()Preps the settings before they’re saved to the database.
raiseEvent()Raises an event.
setSettings()Sets the setting values.

createTables()

Creates any tables defined by the plugin’s records.

IPlugin::createTables()

View source

Returns

void

Signature

public void createTables ( )

dropTables()

Drops any tables defined by the plugin’s records.

IPlugin::dropTables()

View source

Returns

void

Signature

public void dropTables ( )

getDescription()

Returns the plugin’s description.

IPlugin::getDescription()

View source

Returns

string, null – The plugin’s description.

Signature

public string, null getDescription ( )

getDocumentationUrl()

Returns the plugin documentation’s URL.

IPlugin::getDocumentationUrl()

View source

Returns

string, null – The plugin documentation’s URL.

Signature

public string, null getDocumentationUrl ( )

getRecords()

Returns the record classes provided by this plugin.

IPlugin::getRecords()

View source

Arguments

  • $scenario (string, null) – The scenario to initialize the records with.

Returns

Craft\BaseRecord[]

Signature

public Craft\BaseRecord[] getRecords ( $scenario = null )

getReleaseFeedUrl()

Returns the plugin’s releases JSON feed URL.

If the plugin wants to have its updates included in the Updates page, it should provide a JSON feed in the following format:

[
    {
        "version": "0.9.0",
        "downloadUrl": "https://download.craftcommerce.com/0.9/Commerce0.9.0.zip",
        "date": "2015-12-01T10:00:00-08:00",
        "notes": [
            "# Big Stuff",
            "[Added] It’s now possible to create new products right from Product Selector Modals (like the ones used by Products fields).",
            "[Improved] Variants are now defined in a new Variant Matrix field, right on the main Edit Product pages.",
            "# Bug Fixes",
            "[Fixed] Fixed a Twig error that occurred if you manually went to /commerce/orders/new. You now receive a 404 error instead."
        ]
    },
    {
        "version": "0.9.1",
        "downloadUrl": "https://download.craftcommerce.com/0.9/Commerce0.9.1.zip",
        "date": "2015-12-01T11:00:00-08:00",
        "notes": [
            "[Fixed] Fixed a PHP error that occurred when creating a new produt when the current user’s username was ‘null’."
        ]
    }
]

Notes:

  • The feed must be valid JSON.
  • The feed’s URL must begin with “https://” (so it is fetched over SSL).
  • Each release must contain version, downloadUrl, date, and notes attributes.
  • Each release’s downloadUrl must begin with “https://” (so it is downloaded over SSL).
  • Each release’s date must be an ISO-8601-formatted date, as defined by either {@link http://php.net/manual/en/class.datetime.php#datetime.constants.atom DateTime::ATOM} or {@link http://php.net/manual/en/class.datetime.php#datetime.constants.iso8601 DateTime::ISO8601} (with or without the colon between the hours and minutes of the timezone offset).
  • notes can either be a string (with each release note separated by a newline character), or an array.
  • Release note lines that begin with # will be treated as headings.
  • Release note lines that begin with [Added], [Improved], or [Fixed] will be given added, improved, and fixed classes within the Updates page.
  • Release note lines can contain Markdown code, but not HTML.
  • Releases can contain a critical attribute which can be set to true if the release is critical.

IPlugin::getReleaseFeedUrl()

View source

Returns

string, null – The plugin’s release feed URL

Signature

public string, null getReleaseFeedUrl ( )

getSchemaVersion()

Returns the plugin’s schema version number.

Changing the schema version number tells Craft that there are new migration files that need to be run.

IPlugin::getSchemaVersion()

View source

Returns

string, null – The plugin’s version number, or null if it doesn’t need one

Signature

public string, null getSchemaVersion ( )

getSettingsUrl()

Returns the URL to the plugin’s settings page in the CP.

If your plugin requires a custom settings page, you can use this method to point to it.

If this method returns anything, it will be run through {@link UrlHelper::getCpUrl()} before getting output, so a full URL is not necessary.

If this method doesn’t return anything, a simple settings page will be provided for your plugin, filled with whatever {@link getSettingsHtml()} returns.

IPlugin::getSettingsUrl()

View source

Returns

string, null – The URL to the plugin’s settings page, if it has a custom one.

Signature

public string, null getSettingsUrl ( )

getSourceLanguage()

Returns the locale ID that identifies what language the plugin was written in.

IPlugin::getSourceLanguage()

View source

Returns

string – The plugin’s source language.

Signature

public string getSourceLanguage ( )

hasCpSection()

Returns whether this plugin has its own section in the CP.

IPlugin::hasCpSection()

View source

Returns

boolean – Whether this plugin has its own section in the CP.

Signature

public boolean hasCpSection ( )

hasSettings()

Returns whether the plugin has settings.

IPlugin::hasSettings()

View source

Returns

boolean – Whether the plugin has settings

Signature

public boolean hasSettings ( )

log()

A wrapper for writing to the log files for plugins that will ultimately call {@link Craft::log()}. This allows plugins to be able to write to their own log files at craft/storage/runtime/logs/pluginHandle.log using PluginHandle::log() syntax.

View source

Arguments

  • $msg (string) – The message to be logged.
  • $level (string) – The level of the message (e.g. LogLevel::Trace', LogLevel::Info, LogLevel::Warning or LogLevel::Error).
  • $force (boolean) – Whether to force the message to be logged regardless of the level or category.

Returns

mixed

Signature

public static mixed log ( $msg, $level = \Craft\LogLevel::Info, $force = false )

onAfterInstall()

Performs any actions that should occur after the plugin is installed.

IPlugin::onAfterInstall()

View source

Returns

void

Signature

public void onAfterInstall ( )

onBeforeInstall()

Performs any actions that should occur before the plugin is installed.

IPlugin::onBeforeInstall()

View source

Returns

void – Return false to abort plugin installation

Signature

public void onBeforeInstall ( )

onBeforeUninstall()

Performs any actions that should occur before the plugin is uninstalled.

IPlugin::onBeforeUninstall()

View source

Returns

void

Signature

public void onBeforeUninstall ( )

Protected Methods

MethodDescription
defineSettings()Defines the settings.
getSettingsModel()Returns the settings model.