You are here

public function UserPointsTransactor::isApplicable in User Points 8

Check if the transactor is applicable to a particular entity.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The content entity to check.

\Drupal\transaction\TransactionTypeInterface $transaction_type: (optional) Restrict the checking to a particular transaction type.

Return value

bool TRUE if transactor is applicable to the given entity.

Overrides TransactorBase::isApplicable

File

src/Plugin/Transaction/UserPointsTransactor.php, line 187

Class

UserPointsTransactor
Transactor for user points type transactions.

Namespace

Drupal\userpoints\Plugin\Transaction

Code

public function isApplicable(ContentEntityInterface $entity, TransactionTypeInterface $transaction_type = NULL) {

  /** @var \Drupal\user\UserInterface $entity */
  if (parent::isApplicable($entity)) {
    if ($transaction_type) {
      $settings = $transaction_type
        ->getPluginSettings();

      // Apply to any user when no roles in settings.
      return empty($settings['roles']) || !empty(array_intersect($entity
        ->getRoles(TRUE), explode(',', $settings['roles'])));
    }
  }
  return FALSE;
}