ParagraphsBehaviorManager.php in Paragraphs 8
File
src/ParagraphsBehaviorManager.php
View source
<?php
namespace Drupal\paragraphs;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
class ParagraphsBehaviorManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/paragraphs/Behavior', $namespaces, $module_handler, 'Drupal\\paragraphs\\ParagraphsBehaviorInterface', 'Drupal\\paragraphs\\Annotation\\ParagraphsBehavior');
$this
->setCacheBackend($cache_backend, 'paragraphs_behavior_plugins');
$this
->alterInfo('paragraphs_behavior_info');
}
public function getDefinitions() {
$definitions = parent::getDefinitions();
uasort($definitions, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
return $definitions;
}
public function getApplicableDefinitions($paragraphs_type) {
$definitions = $this
->getDefinitions();
$applicable_plugins = [];
foreach ($definitions as $key => $definition) {
if ($definition['class']::isApplicable($paragraphs_type)) {
$applicable_plugins[$key] = $definition;
}
}
return $applicable_plugins;
}
}