You are here

protected function UserBlock::buildRoleSelectBox in Content Planner 8

Build Role select box.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

\Symfony\Component\HttpFoundation\Request|null $request: The current request.

array $block_configuration: The block configuration.

Return value

array The roles checkboxes.

1 call to UserBlock::buildRoleSelectBox()
UserBlock::getConfigSpecificFormFields in src/Plugin/DashboardBlock/UserBlock.php
Add additonal form elements specific to the Plugin.

File

src/Plugin/DashboardBlock/UserBlock.php, line 175

Class

UserBlock
Provides a user block for Content Planner Dashboard.

Namespace

Drupal\content_planner\Plugin\DashboardBlock

Code

protected function buildRoleSelectBox(FormStateInterface &$form_state, Request &$request, array $block_configuration) {

  // Get Roles.
  $roles = Role::loadMultiple();
  $roles_options = [];
  foreach ($roles as $role_id => $role) {
    if (in_array($role_id, [
      'anonymous',
    ])) {
      continue;
    }
    $roles_options[$role_id] = $role
      ->label();
  }
  $default_value = isset($block_configuration['plugin_specific_config']['roles']) ? $block_configuration['plugin_specific_config']['roles'] : [];
  return [
    '#type' => 'checkboxes',
    '#title' => t('Which Roles to display'),
    '#description' => t('Select which Roles should be displayed in the block.'),
    '#required' => TRUE,
    '#options' => $roles_options,
    '#default_value' => $default_value,
  ];
}