class ParagraphsBehaviorManager

Plugin type manager for paragraphs type behavior plugins.

Hierarchy

Expanded class hierarchy of ParagraphsBehaviorManager

1 file declares its use of ParagraphsBehaviorManager
1 string reference to 'ParagraphsBehaviorManager'
paragraphs.services.yml in paragraphs/paragraphs.services.yml
paragraphs/paragraphs.services.yml

File

paragraphs/src/ParagraphsBehaviorManager.php, line 14

Namespace

Drupal\paragraphs
View source
class ParagraphsBehaviorManager extends DefaultPluginManager {

  /**
   * Constructs a ParagraphsBehaviorManager object.
   *
   * @param \Traversable $namespaces
   *   An object that implements \Traversable which contains the root paths
   *   keyed by the corresponding namespace to look for plugin implementations.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
   *   Cache backend instance to use.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler.
   */
  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');
  }

  /**
   * {@inheritdoc}
   */
  public function getDefinitions() {
    $definitions = parent::getDefinitions();
    uasort($definitions, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
    return $definitions;
  }

  /**
   * Gets the applicable behavior plugins.
   *
   * Loop over the plugin definitions, check the applicability of each one of
   * them and return the array of the applicable plugins.
   *
   * @return array
   *   The applicable behavior plugins.
   */
  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;
  }

}

Members

Name Modifiers Type Descriptionsort descending Overrides
ParagraphsBehaviorManager::getDefinitions public function
ParagraphsBehaviorManager::__construct public function Constructs a ParagraphsBehaviorManager object.
ParagraphsBehaviorManager::getApplicableDefinitions public function Gets the applicable behavior plugins.