A collection of tips.
Expanded class hierarchy of TipsBag
class TipsBag extends PluginBag {
/**
* The initial configuration for each tip in the bag.
*
* @var array
* An associative array containing the initial configuration for each tip
* in the bag, keyed by plugin instance ID.
*/
protected $configurations = array();
/**
* The manager used to instantiate the plugins.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $manager;
/**
* Constructs a TipsBag object.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $manager
* The manager to be used for instantiating plugins.
* @param array $configurations
* (optional) An associative array containing the initial configuration for
* each tour in the bag, keyed by plugin instance ID.
*/
public function __construct(PluginManagerInterface $manager, array $configurations = array()) {
$this->manager = $manager;
$this->configurations = $configurations;
if (!empty($configurations)) {
$this->instanceIDs = array_combine(array_keys($configurations), array_keys($configurations));
}
}
/**
* Overrides \Drupal\Component\Plugin\PluginBag::initializePlugin().
*/
protected function initializePlugin($instance_id) {
// If the tip was initialized before, just return.
if (isset($this->pluginInstances[$instance_id])) {
return;
}
$type = $this->configurations[$instance_id]['plugin'];
$definition = $this->manager
->getDefinition($type);
if (isset($definition)) {
$this
->addInstanceID($instance_id);
$configuration = $definition;
// Merge the actual configuration into the default configuration.
if (isset($this->configurations[$instance_id])) {
$configuration = NestedArray::mergeDeep($configuration, $this->configurations[$instance_id]);
}
$this->pluginInstances[$instance_id] = $this->manager
->createInstance($type, $configuration);
}
else {
throw new PluginException(format_string("Unknown tip plugin ID '@tip'.", array(
'@tip' => $instance_id,
)));
}
}
}
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PluginBag:: |
protected | property | Stores the IDs of all potential plugin instances. | |
PluginBag:: |
protected | property | Stores all instantiated plugins. | |
PluginBag:: |
public | function | Adds an instance ID to the array of available instance IDs. | |
PluginBag:: |
public | function | Clears all instantiated plugins. | 1 |
PluginBag:: |
public | function | Implements \Countable::count(). | |
PluginBag:: |
public | function | Implements \Iterator::current(). | |
PluginBag:: |
public | function | Retrieves a plugin instance, initializing it if necessary. | |
PluginBag:: |
public | function | Returns all instance IDs. | |
PluginBag:: |
public | function | Determines if a plugin instance exists. | |
PluginBag:: |
public | function | Implements \Iterator::key(). | |
PluginBag:: |
public | function | Implements \Iterator::next(). | |
PluginBag:: |
public | function | Removes an initialized plugin. | 1 |
PluginBag:: |
public | function | Implements \Iterator::rewind(). | |
PluginBag:: |
public | function | Stores an initialized plugin. | |
PluginBag:: |
public | function | Sets the instance IDs property. | |
PluginBag:: |
public | function | Implements \Iterator::valid(). | |
TipsBag:: |
protected | property | The initial configuration for each tip in the bag. | |
TipsBag:: |
protected | property | The manager used to instantiate the plugins. | |
TipsBag:: |
protected | function |
Overrides \Drupal\Component\Plugin\PluginBag::initializePlugin(). Overrides PluginBag:: |
|
TipsBag:: |
public | function | Constructs a TipsBag object. |