ReCaptchaV3ActionListBuilder.php in reCAPTCHA v3 8
File
src/ReCaptchaV3ActionListBuilder.php
View source
<?php
namespace Drupal\recaptcha_v3;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
class ReCaptchaV3ActionListBuilder extends ConfigEntityListBuilder {
protected $challengeTypes;
public function buildHeader() {
$header['label'] = $this
->t('Label');
$header['id'] = $this
->t('Action');
$header['threshold'] = $this
->t('Threshold');
$header['challenge'] = $this
->t('Fail challenge');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
$row['id'] = $entity
->id();
$row['threshold'] = $entity
->getThreshold();
$challenge_type = $entity
->getChallenge();
$row['challenge'] = $this
->getCaptchaChallengeTypes()[$challenge_type] ?? $this
->t('Not defined');
return $row + parent::buildRow($entity);
}
protected function getCaptchaChallengeTypes() {
if ($this->challengeTypes === NULL) {
$this->challengeTypes = \Drupal::service('captcha.helper')
->getAvailableChallengeTypes(FALSE);
$this->challengeTypes = array_filter($this->challengeTypes, static function ($captcha_type) {
return !(strpos($captcha_type, 'recaptcha_v3') === 0);
}, ARRAY_FILTER_USE_KEY);
$default = \Drupal::config('recaptcha_v3.settings')
->get('default_challenge');
$this->challengeTypes['default'] = $this->challengeTypes[$default] ?? $this
->t('Default');
}
return $this->challengeTypes;
}
}