You are here

public function ConsentUserResolverPluginManager::getDefinitionForType in General Data Protection Regulation 8

Same name and namespace in other branches
  1. 8.2 modules/gdpr_consent/src/ConsentUserResolver/ConsentUserResolverPluginManager.php \Drupal\gdpr_consent\ConsentUserResolver\ConsentUserResolverPluginManager::getDefinitionForType()
  2. 3.0.x modules/gdpr_consent/src/ConsentUserResolver/ConsentUserResolverPluginManager.php \Drupal\gdpr_consent\ConsentUserResolver\ConsentUserResolverPluginManager::getDefinitionForType()

Check for an existing resolver for the specified entity type/bundle.

Parameters

string $entityType: The entity type.

string $bundle: The bundle.

Return value

array|bool The resolver definition, if it exists, or NULL.

Throws

\Exception

1 call to ConsentUserResolverPluginManager::getDefinitionForType()
ConsentUserResolverPluginManager::getForEntityType in modules/gdpr_consent/src/ConsentUserResolver/ConsentUserResolverPluginManager.php
Finds a resolver for the specified entity type/bundle.

File

modules/gdpr_consent/src/ConsentUserResolver/ConsentUserResolverPluginManager.php, line 65

Class

ConsentUserResolverPluginManager
Class ConsentUserResolverPluginManager.

Namespace

Drupal\gdpr_consent\ConsentUserResolver

Code

public function getDefinitionForType($entityType, $bundle) {
  $definitions = $this
    ->getDefinitions();

  // Get all plugins that act on the entity type.
  $definitionsForEntity = \array_filter($definitions, function ($definition) use ($entityType) {
    return $definition['entityType'] === $entityType;
  });
  $definitionsForBundle = \array_filter($definitionsForEntity, function ($definition) use ($bundle) {
    return array_key_exists('bundle', $definition) && $definition['bundle'] === $bundle;
  });
  $definition = NULL;
  if (\count($definitionsForBundle) > 0) {

    // Get first item from the array.
    $definition = \reset($definitionsForBundle);
  }
  elseif (\count($definitionsForEntity) > 0) {

    // None matched for bundle.
    // Find any with no bundle.
    $definitionsForBundle = \array_filter($definitionsForEntity, function ($definition) {
      return !array_key_exists('bundle', $definition) || $definition['bundle'] === '';
    });
    if (\count($definitionsForBundle) > 0) {

      // Get first item from array.
      $definition = \reset($definitionsForBundle);
    }
  }
  if (NULL === $definition) {
    return FALSE;
  }
  return $definition;
}