You are here

protected function ViewsBulkOperationsActionManager::findDefinitions in Views Bulk Operations (VBO) 8.3

Same name and namespace in other branches
  1. 8 src/Service/ViewsBulkOperationsActionManager.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager::findDefinitions()
  2. 8.2 src/Service/ViewsBulkOperationsActionManager.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager::findDefinitions()
  3. 4.0.x src/Service/ViewsBulkOperationsActionManager.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionManager::findDefinitions()

Finds plugin definitions.

Return value

array List of definitions to store in cache.

Overrides DefaultPluginManager::findDefinitions

1 call to ViewsBulkOperationsActionManager::findDefinitions()
ViewsBulkOperationsActionManager::getDefinitions in src/Service/ViewsBulkOperationsActionManager.php

File

src/Service/ViewsBulkOperationsActionManager.php, line 77

Class

ViewsBulkOperationsActionManager
Defines Views Bulk Operations action manager.

Namespace

Drupal\views_bulk_operations\Service

Code

protected function findDefinitions() {
  $definitions = $this
    ->getDiscovery()
    ->getDefinitions();
  $entity_type_definitions = $this->entityTypeManager
    ->getDefinitions();
  foreach ($definitions as $plugin_id => &$definition) {

    // We only allow actions of existing entity type and empty
    // type meaning it's applicable to all entity types.
    if (empty($definition) || !empty($definition['type']) && !isset($entity_type_definitions[$definition['type']])) {
      unset($definitions[$plugin_id]);
    }

    // Filter definitions that are incompatible due to applied core
    // configuration form workaround (using confirm_form_route for config
    // forms and using action execute() method for purposes other than
    // actual action execution). Also filter out actions that don't implement
    // ViewsBulkOperationsActionInterface and have empty type as this
    // shouldn't be the case in core. Luckily, core also has useful actions
    // without the workaround, like node_assign_owner_action or
    // comment_unpublish_by_keyword_action.
    if (!in_array('Drupal\\views_bulk_operations\\Action\\ViewsBulkOperationsActionInterface', class_implements($definition['class']))) {
      if (!empty($definition['confirm_form_route_name']) || empty($definition['type'])) {
        unset($definitions[$plugin_id]);
      }
    }
    $this
      ->processDefinition($definition, $plugin_id);
  }
  $this
    ->alterDefinitions($definitions);
  foreach ($definitions as $plugin_id => $plugin_definition) {

    // If the plugin definition is an object, attempt to convert it to an
    // array, if that is not possible, skip further processing.
    if (is_object($plugin_definition) && !($plugin_definition = (array) $plugin_definition)) {
      continue;
    }

    // If this plugin was provided by a module that does not exist, remove the
    // plugin definition.
    if (isset($plugin_definition['provider']) && !in_array($plugin_definition['provider'], [
      'core',
      'component',
    ]) && !$this
      ->providerExists($plugin_definition['provider'])) {
      unset($definitions[$plugin_id]);
    }
  }
  return $definitions;
}