class TamperPluginDefinition in Tamper 7
Wraps a plugin definition array.
Hierarchy
- class \TamperPluginDefinition
Expanded class hierarchy of TamperPluginDefinition
File
- src/
Tamper.php, line 11 - Contains TamperPluginBase.
View source
class TamperPluginDefinition {
/**
* The plugin definition id.
*
* @var string
*/
protected $id;
/**
* The plugin definition.
*
* @var array
*/
protected $definition;
/**
* Constructs a TamperPluginDefinition object.
*
* @param string $definition_id
* The plugin definition id.
* @param array $definition
* The definition array.
*/
public function __construct($definition_id, array $definition) {
$this->id = $definition_id;
$this->definition = $definition;
}
/**
* Returns a single plugin definition.
*
* @param string $id
* The plugin definition id.
*
* @return self
* A plugin definition object.
*/
public static function load($id) {
ctools_include('plugins');
return new self($id, ctools_get_plugins('tamper', 'plugins', $id));
}
/**
* Returns all plugin definitions.
*
* @return []TamperPluginDefinition
* A list of all available plugin definitions.
*/
public static function loadAll() {
ctools_include('plugins');
$definitions = array();
foreach (ctools_get_plugins('tamper', 'plugins') as $id => $definition) {
$definitions[$id] = new self($id, $definition);
}
return $definitions;
}
/**
* Returns the plugin id.
*
* @return string
* The plugin id.
*/
public function getId() {
return $this->id;
}
/**
* Returns the definition label.
*
* @return string
* The label of the plugin.
*/
public function getLabel() {
return $this->definition['name'];
}
/**
* Returns the plugin class.
*
* @return string
* The plugin class.
*/
protected function getClass() {
return $this->definition['class']['class'];
}
/**
* Determines whether this plugin is compatible with a given module.
*
* @param string $module
* The module to check.
*
* @return bool
* Returns true if compatible, and false if not.
*/
public function isCompatible($module) {
return empty($this->definition['compatible']) || in_array($module, $this->definition['compatible'], TRUE);
}
/**
* Creates a plugin instance.
*
* @param array $configuration
* (optional) The configuration of the plugin.
*
* @return TamperPluginInterface
* Returns the newly constructed plugin.
*/
public function createInstance(array $configuration = array()) {
$class = $this
->getClass();
return new $class($configuration, $this->id, $this);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TamperPluginDefinition:: |
protected | property | The plugin definition. | |
TamperPluginDefinition:: |
protected | property | The plugin definition id. | |
TamperPluginDefinition:: |
public | function | Creates a plugin instance. | |
TamperPluginDefinition:: |
protected | function | Returns the plugin class. | |
TamperPluginDefinition:: |
public | function | Returns the plugin id. | |
TamperPluginDefinition:: |
public | function | Returns the definition label. | |
TamperPluginDefinition:: |
public | function | Determines whether this plugin is compatible with a given module. | |
TamperPluginDefinition:: |
public static | function | Returns a single plugin definition. | |
TamperPluginDefinition:: |
public static | function | Returns all plugin definitions. | |
TamperPluginDefinition:: |
public | function | Constructs a TamperPluginDefinition object. |