function context_groups_add_groups_to_table in Context groups 8
Same name and namespace in other branches
- 8.2 includes/context_groups_ui.inc \context_groups_add_groups_to_table()
Add context groups to the reaction table.
Parameters
array $table: Reference to reaction table.
object $params: List of parameters from context groups.
Context $context: Context object.
array $regions: List of regions.
1 call to context_groups_add_groups_to_table()
- context_groups_reaction_ui_display_form_alter in includes/
context_groups_ui.inc - Alter the reaction table display.
File
- includes/
context_groups_ui.inc, line 190 - Altering display for reaction table.
Code
function context_groups_add_groups_to_table(array &$table, $params, Context $context, array $regions) {
foreach ($params->groups_by_region as $group_array) {
foreach ($group_array as $context_group) {
$operations = [];
if (Drupal::currentUser()
->hasPermission('create context groups')) {
$operations = [
'#type' => 'operations',
'#links' => [
'edit' => [
'title' => t('Edit'),
'url' => Url::fromRoute('context_groups.group_edit_form', [
'context' => $context
->id(),
'context_group' => $context_group['name'],
]),
'attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 500,
]),
],
],
'delete' => [
'title' => t('Delete'),
'url' => Url::fromRoute('context_groups.group_delete_form', [
'context' => $context
->id(),
'context_group' => $context_group['name'],
]),
'attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 1000,
]),
],
],
],
];
}
$table[$context_group['id']] = [
'#attributes' => [
'class' => [
'draggable context-group',
],
'data-region' => 'region-' . $context_group['region'],
'data-group-id' => $context_group['id'],
],
'#region_callback' => 'context_groups_region_callback',
'title' => [
'#markup' => '' . $context_group['label'] . '',
],
'category' => [],
'unique' => [],
'weight' => [
'#type' => 'textfield',
'#default_value' => $context_group['weight'],
'#size' => 3,
'#title' => 'Weight for row',
'#title_display' => 'invisible',
'#attributes' => [
'class' => [
'field-weight',
],
],
],
'region' => [
'#type' => 'select',
'#title' => t('Region'),
'#title_display' => 'invisible',
'#default_value' => $context_group['region'],
'#options' => $regions,
'#attributes' => [
'class' => [
'block-region-select',
'block-region-' . $context_group['region'],
],
],
],
'parent_wrapper' => [
'parent' => [
'#type' => 'select',
'#attributes' => [
'class' => [
'field-parent',
],
],
'#options' => $params->group_list,
'#default_value' => $context_group['parent'],
],
],
'operations' => $operations,
];
}
}
}