3 namespace Drupal\paragraphs;
5 use Drupal\Core\Cache\CacheBackendInterface;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\Plugin\DefaultPluginManager;
10 * Plugin type manager for paragraphs type behavior plugins.
12 * @ingroup paragraphs_behavior
14 class ParagraphsBehaviorManager extends DefaultPluginManager {
17 * Constructs a ParagraphsBehaviorManager object.
19 * @param \Traversable $namespaces
20 * An object that implements \Traversable which contains the root paths
21 * keyed by the corresponding namespace to look for plugin implementations.
22 * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
23 * Cache backend instance to use.
24 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
27 public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
28 parent::__construct('Plugin/paragraphs/Behavior', $namespaces, $module_handler, 'Drupal\paragraphs\ParagraphsBehaviorInterface', 'Drupal\paragraphs\Annotation\ParagraphsBehavior');
29 $this->setCacheBackend($cache_backend, 'paragraphs_behavior_plugins');
30 $this->alterInfo('paragraphs_behavior_info');
36 public function getDefinitions() {
37 $definitions = parent::getDefinitions();
38 uasort($definitions, 'Drupal\Component\Utility\SortArray::sortByWeightElement');
43 * Gets the applicable behavior plugins.
45 * Loop over the plugin definitions, check the applicability of each one of
46 * them and return the array of the applicable plugins.
49 * The applicable behavior plugins.
51 public function getApplicableDefinitions($paragraphs_type) {
52 $definitions = $this->getDefinitions();
53 $applicable_plugins = [];
54 foreach ($definitions as $key => $definition) {
55 if ($definition['class']::isApplicable($paragraphs_type)) {
56 $applicable_plugins[$key] = $definition;
59 return $applicable_plugins;