You are here

public function RoleBasedGlobalText::render in Views Role Based Global Text 8

Same name and namespace in other branches
  1. 8.2 src/RoleBasedGlobalText.php \Drupal\views_role_based_global_text\RoleBasedGlobalText::render()

Render the area.

Parameters

bool $empty: (optional) Indicator if view result is empty or not. Defaults to FALSE.

Return value

array In any case we need a valid Drupal render array to return.

Overrides Text::render

File

src/RoleBasedGlobalText.php, line 44

Class

RoleBasedGlobalText
Class RoleBasedGlobalText.

Namespace

Drupal\views_role_based_global_text

Code

public function render($empty = FALSE) {

  // Get the checked roles.
  $checked_roles = $this->options['roles_fieldset'] && is_array($this->options['roles_fieldset']['roles']) ? array_filter($this->options['roles_fieldset']['roles']) : [];

  // Roles assigned to logged-in users.
  $user_roles = \Drupal::currentUser()
    ->getRoles();
  if (empty($checked_roles) || array_intersect($user_roles, $checked_roles)) {
    return parent::render($empty);
  }
  return [];
}