You are here

class TamperPluginDefinition in Tamper 7

Wraps a plugin definition array.

Hierarchy

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

Namesort descending Modifiers Type Description Overrides
TamperPluginDefinition::$definition protected property The plugin definition.
TamperPluginDefinition::$id protected property The plugin definition id.
TamperPluginDefinition::createInstance public function Creates a plugin instance.
TamperPluginDefinition::getClass protected function Returns the plugin class.
TamperPluginDefinition::getId public function Returns the plugin id.
TamperPluginDefinition::getLabel public function Returns the definition label.
TamperPluginDefinition::isCompatible public function Determines whether this plugin is compatible with a given module.
TamperPluginDefinition::load public static function Returns a single plugin definition.
TamperPluginDefinition::loadAll public static function Returns all plugin definitions.
TamperPluginDefinition::__construct public function Constructs a TamperPluginDefinition object.