Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / paragraphs / src / ParagraphsBehaviorCollection.php
1 <?php
2
3 namespace Drupal\paragraphs;
4
5 use Drupal\Core\Plugin\DefaultLazyPluginCollection;
6
7 /**
8  * A collection of paragraphs behavior plugins.
9  */
10 class ParagraphsBehaviorCollection extends DefaultLazyPluginCollection {
11
12   /**
13    * All behavior plugin definitions.
14    *
15    * @var array
16    */
17   protected $definitions;
18
19   /**
20    * {@inheritdoc}
21    *
22    * @return \Drupal\paragraphs\ParagraphsBehaviorInterface
23    */
24   public function &get($instance_id) {
25     return parent::get($instance_id);
26   }
27
28   /**
29    * Retrieves all enabled behavior plugins.
30    */
31   public function getEnabled() {
32     $this->getAll();
33     $enabled = [];
34     foreach ($this->getConfiguration() as $key => $value) {
35       if (isset($value['enabled']) && $value['enabled'] == TRUE) {
36         $enabled[$key] = $this->get($key);
37       }
38     }
39     return $enabled;
40   }
41
42   /**
43    * Retrieves all behavior plugins definitions and creates an instance for each
44    * one.
45    */
46   public function getAll() {
47     // Retrieve all available behavior plugin definitions.
48     if (!$this->definitions) {
49       $this->definitions = $this->manager->getDefinitions();
50     }
51     // Ensure that there is an instance of all available behavior plugins.
52     // Note that getDefinitions() are keyed by $plugin_id. $instance_id is the
53     // $plugin_id for behavior plugins, since a single behavior plugin can only
54     // exist once in a paragraphs type.
55     foreach ($this->definitions as $plugin_id => $definition) {
56       if (!isset($this->pluginInstances[$plugin_id])) {
57         $this->initializePlugin($plugin_id);
58       }
59     }
60     return $this->pluginInstances;
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   protected function initializePlugin($instance_id) {
67     $configuration = isset($this->configurations[$instance_id]) ? $this->configurations[$instance_id] : [];
68     $this->set($instance_id, $this->manager->createInstance($instance_id, $configuration));
69   }
70
71 }