ParagraphsBehaviorCollection.php in Paragraphs 8
File
src/ParagraphsBehaviorCollection.php
View source
<?php
namespace Drupal\paragraphs;
use Drupal\Core\Plugin\DefaultLazyPluginCollection;
class ParagraphsBehaviorCollection extends DefaultLazyPluginCollection {
protected $definitions;
public function &get($instance_id) {
return parent::get($instance_id);
}
public function getEnabled() {
$this
->getAll();
$enabled = [];
foreach ($this
->getConfiguration() as $key => $value) {
if (isset($value['enabled']) && $value['enabled'] == TRUE) {
$enabled[$key] = $this
->get($key);
}
}
return $enabled;
}
public function getAll() {
if (!$this->definitions) {
$this->definitions = $this->manager
->getDefinitions();
}
foreach ($this->definitions as $plugin_id => $definition) {
if (!isset($this->pluginInstances[$plugin_id])) {
$this
->initializePlugin($plugin_id);
}
}
return $this->pluginInstances;
}
protected function initializePlugin($instance_id) {
$configuration = isset($this->configurations[$instance_id]) ? $this->configurations[$instance_id] : [];
$this
->set($instance_id, $this->manager
->createInstance($instance_id, $configuration));
}
}