BasePlugin

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

Plugin base class.

See also http://craftcms.com

View source (opens new window)

# Public Properties

# $isEnabled

Signature

public boolean $isEnabled = false

# $isInstalled

Signature

public boolean $isInstalled = false

# Protected Properties

# $componentType

Signature

protected string $componentType = 'Plugin'

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__get() (opens new window) Returns a property value, an event handler list or a behavior based on its name.
__isset() (opens new window) Checks if a property value is null.
__set() (opens new window) Sets value of a component property.
__unset() (opens new window) Sets a component property to be null.
asa() (opens new window) Returns the named behavior object.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
attachEventHandler() (opens new window) Attaches an event handler to an event.
canGetProperty() (opens new window) Determines whether a property can be read.
canSetProperty() (opens new window) Determines whether a property can be set.
createTables() Creates any tables defined by the plugin’s records.
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
detachEventHandler() (opens new window) Detaches an existing event handler.
disableBehavior() (opens new window) Disables an attached behavior.
disableBehaviors() (opens new window) Disables all behaviors attached to this component.
dropTables() Drops any tables defined by the plugin’s records.
enableBehavior() (opens new window) Enables an attached behavior.
enableBehaviors() (opens new window) Enables all behaviors attached to this component.
evaluateExpression() (opens new window) 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() (opens new window) Returns the list of attached event handlers for an event.
getIsInitialized() (opens new window) 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() (opens new window) Determines whether an event is defined.
hasEventHandler() (opens new window) Checks whether the named event has attached handlers.
hasProperty() (opens new window) Determines whether a property is defined.
hasSettings() Returns whether the plugin has settings.
init() (opens new window) 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() (opens new window) Raises an event.
setSettings() Sets the setting values.

# createTables()

Creates any tables defined by the plugin’s records.

IPlugin::createTables()

View source (opens new window)

Returns

void

Signature

public void createTables ( )

# dropTables()

Drops any tables defined by the plugin’s records.

IPlugin::dropTables()

View source (opens new window)

Returns

void

Signature

public void dropTables ( )

# getDescription()

Returns the plugin’s description.

IPlugin::getDescription()

View source (opens new window)

Returns

string (opens new window), null (opens new window) – The plugin’s description.

Signature

public string, null getDescription ( )

# getDocumentationUrl()

Returns the plugin documentation’s URL.

IPlugin::getDocumentationUrl()

View source (opens new window)

Returns

string (opens new window), null (opens new window) – The plugin documentation’s URL.

Signature

public string, null getDocumentationUrl ( )

# getRecords()

Returns the record classes provided by this plugin.

IPlugin::getRecords()

View source (opens new window)

Arguments

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 (opens new window)

Returns

string (opens new window), null (opens new window) – 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 (opens new window)

Returns

string (opens new window), null (opens new window) – 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 (opens new window)

Returns

string (opens new window), null (opens new window) – 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 (opens new window)

Returns

string (opens new window) – 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 (opens new window)

Returns

boolean (opens new window) – 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 (opens new window)

Returns

boolean (opens new window) – 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 (opens new window)

Arguments

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 (opens new window)

Returns

void

Signature

public void onAfterInstall ( )

# onBeforeInstall()

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

IPlugin::onBeforeInstall()

View source (opens new window)

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 (opens new window)

Returns

void

Signature

public void onBeforeUninstall ( )

# Protected Methods

Method Description
defineSettings() Defines the settings.
getSettingsModel() Returns the settings model.