You are here

protected function AssetInjectorAccessControlHandler::resolveThemeConditions in Asset Injector 8.2

Resolve only current_theme condition plugins.

Parameters

\Drupal\asset_injector\AssetInjectorInterface $entity: The asset with theme conditions.

Return value

bool If the theme condition resolves true or not.

Throws

\Drupal\Component\Plugin\Exception\PluginException

1 call to AssetInjectorAccessControlHandler::resolveThemeConditions()
AssetInjectorAccessControlHandler::checkAccess in src/AssetInjectorAccessControlHandler.php
Performs access checks.

File

src/AssetInjectorAccessControlHandler.php, line 149

Class

AssetInjectorAccessControlHandler
Defines the access control handler for the asset_injector entity types.

Namespace

Drupal\asset_injector

Code

protected function resolveThemeConditions(AssetInjectorInterface $entity) {
  $conditions = $entity
    ->getConditionsCollection();
  $theme_conditions = [];

  // If no current theme condition, return true.
  if (!$conditions
    ->has('current_theme')) {
    return TRUE;
  }

  /** @var \Drupal\system\Plugin\Condition\CurrentThemeCondition $theme_condition */
  $theme_condition = $conditions
    ->get('current_theme');
  $config = $theme_condition
    ->getConfig();
  foreach ($config['theme'] as $theme) {
    $new_theme_conditions = clone $theme_condition;
    $new_theme_conditions
      ->setConfig('theme', $theme);
    $conditions
      ->set("current_theme_{$theme}", $new_theme_conditions);
    $theme_conditions[] = $new_theme_conditions;
  }
  $logic = $config['negate'] ? 'and' : 'or';
  return $this
    ->resolveConditions($theme_conditions, $logic);
}