Issue #2283969 by tim.plunkett: Add a protected BlockBase::blockAccess() to contain plugin-specific logic.

8.0.x
webchick 2014-06-11 14:31:42 -07:00
parent 5f6ca548ac
commit 12317b75fd
12 changed files with 28 additions and 13 deletions

View File

@ -100,7 +100,7 @@ class AggregatorFeedBlock extends BlockBase implements ContainerFactoryPluginInt
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
protected function blockAccess(AccountInterface $account) {
// Only grant access to users with the 'access news feeds' permission.
return $account->hasPermission('access news feeds');
}

View File

@ -112,8 +112,23 @@ abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginIn
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
// By default, the block is visible unless user-configured rules indicate
// that it should be hidden.
// @todo Move block visibility here in https://drupal.org/node/2278541.
return $this->blockAccess($account);
}
/**
* Indicates whether the block should be shown.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The user session for which to check access.
*
* @return bool
* TRUE if the block should be shown, or FALSE otherwise.
*
* @see self::access()
*/
protected function blockAccess(AccountInterface $account) {
// By default, the block is visible.
return TRUE;
}

View File

@ -32,7 +32,7 @@ class TestBlockInstantiation extends BlockBase {
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
protected function blockAccess(AccountInterface $account) {
return $account->hasPermission('access content');
}

View File

@ -56,7 +56,7 @@ abstract class ForumBlockBase extends BlockBase {
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
protected function blockAccess(AccountInterface $account) {
return $account->hasPermission('access content');
}

View File

@ -66,7 +66,7 @@ class LanguageBlock extends BlockBase implements ContainerFactoryPluginInterface
/**
* {@inheritdoc}
*/
function access(AccountInterface $account) {
protected function blockAccess(AccountInterface $account) {
return $this->languageManager->isMultilingual();
}

View File

@ -33,7 +33,7 @@ class SyndicateBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
protected function blockAccess(AccountInterface $account) {
return $account->hasPermission('access content');
}

View File

@ -26,7 +26,7 @@ class SearchBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
protected function blockAccess(AccountInterface $account) {
return $account->hasPermission('search content');
}

View File

@ -55,7 +55,7 @@ class StatisticsPopularBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
protected function blockAccess(AccountInterface $account) {
if ($account->hasPermission('access content')) {
$daytop = $this->configuration['top_day_num'];
if (!$daytop || !($result = statistics_title_list('daycount', $daytop)) || !($this->day_list = node_title_list($result, t("Today's:")))) {

View File

@ -78,7 +78,7 @@ class SystemHelpBlock extends BlockBase implements ContainerFactoryPluginInterfa
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
protected function blockAccess(AccountInterface $account) {
$this->help = $this->getActiveHelp($this->request);
return (bool) $this->help;
}

View File

@ -66,7 +66,7 @@ class RedirectFormBlock extends BlockBase implements ContainerFactoryPluginInter
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
protected function blockAccess(AccountInterface $account) {
return TRUE;
}

View File

@ -25,7 +25,7 @@ class UserLoginBlock extends BlockBase {
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
protected function blockAccess(AccountInterface $account) {
$route_name = \Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME);
return ($account->isAnonymous() && !in_array($route_name, array('user.register', 'user.login', 'user.logout')));
}

View File

@ -91,7 +91,7 @@ abstract class ViewsBlockBase extends BlockBase implements ContainerFactoryPlugi
/**
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
protected function blockAccess(AccountInterface $account) {
return $this->view->access($this->displayID);
}