Skip to content
Snippets Groups Projects

#3259797 Add blockAccess to control block visibility if Klaro not enabled

@@ -2,9 +2,11 @@
namespace Drupal\simple_klaro\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -58,14 +60,21 @@ class PreferencesDialog extends BlockBase implements ContainerFactoryPluginInter
*/
public function build() {
$config = $this->configFactory->get('simple_klaro.settings');
$klaro_enabled = $config->get('enabled');
if (!$klaro_enabled) {
return FALSE;
}
return [
'#markup' => '<a href="#" id="klaro-preferences">' . $config->get('preferences') . '</a>',
];
}
/**
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account) {
$config = $this->configFactory->get('simple_klaro.settings');
$klaro_enabled = $config->get('enabled');
if (!$klaro_enabled) {
return AccessResult::forbidden();
}
return parent::blockAccess($account);
}
}
Loading