function social_topic_form_views_exposed_form_alter in Open Social 8.6
Same name and namespace in other branches
- 8.9 modules/social_features/social_topic/social_topic.module \social_topic_form_views_exposed_form_alter()
- 8 modules/social_features/social_topic/social_topic.module \social_topic_form_views_exposed_form_alter()
- 8.2 modules/social_features/social_topic/social_topic.module \social_topic_form_views_exposed_form_alter()
- 8.3 modules/social_features/social_topic/social_topic.module \social_topic_form_views_exposed_form_alter()
- 8.4 modules/social_features/social_topic/social_topic.module \social_topic_form_views_exposed_form_alter()
- 8.5 modules/social_features/social_topic/social_topic.module \social_topic_form_views_exposed_form_alter()
- 8.7 modules/social_features/social_topic/social_topic.module \social_topic_form_views_exposed_form_alter()
- 8.8 modules/social_features/social_topic/social_topic.module \social_topic_form_views_exposed_form_alter()
- 10.3.x modules/social_features/social_topic/social_topic.module \social_topic_form_views_exposed_form_alter()
- 10.0.x modules/social_features/social_topic/social_topic.module \social_topic_form_views_exposed_form_alter()
- 10.1.x modules/social_features/social_topic/social_topic.module \social_topic_form_views_exposed_form_alter()
- 10.2.x modules/social_features/social_topic/social_topic.module \social_topic_form_views_exposed_form_alter()
Implements hook_form_form_ID_alter().
Enhance the exposed filter form of the topic overview.
File
- modules/
social_features/ social_topic/ social_topic.module, line 69 - The Social topic module.
Code
function social_topic_form_views_exposed_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// On user topics overview.
if ($form['#id'] === 'views-exposed-form-topics-page-profile') {
$form['type']['#options']['All'] = t('All types');
$form['status']['#options'][0] = t('Unpublished');
$form['status']['#options'][1] = t('Published');
$account_uid = \Drupal::routeMatch()
->getParameter('user');
$current_uid = \Drupal::currentUser()
->id();
if ($account_uid !== $current_uid) {
$form['status']['#access'] = FALSE;
}
// Enable the reset button.
// @todo make sure the block content refreshes on submit as well (AJAX).
$form['actions']['reset']['#access'] = TRUE;
// @todo make sure exposed form filtering redirects to the proper view
// page, when views is updated.
$form['#action'] = '/user/' . $account_uid . '/topics';
}
// On group topics overview.
if ($form['#id'] === 'views-exposed-form-group-topics-page-group-topics') {
$group_from_route = _social_group_get_current_group();
$current_user = \Drupal::currentUser();
$membership = FALSE;
$group_membership = $group_from_route
->getMember($current_user);
if ($group_membership) {
$membership = TRUE;
}
if (!empty($form['status'])) {
$form['status']['#options']['All'] = t('All statuses');
$form['status']['#options'][0] = t('Unpublished');
$form['status']['#options'][1] = t('Published');
// Only show the unpublished option when you are member of the group.
// You can't place content in a group you are not a member of anyway.
if (!$membership) {
$form['status']['#access'] = FALSE;
}
}
$form['type']['#options']['All'] = t('All types');
// Get group from route.
if (!empty($group_from_route)) {
$group_id = $group_from_route
->id();
}
$form['actions']['reset']['#access'] = TRUE;
// Make sure we redirect to the current group page.
$form['#action'] = '/group/' . $group_id . '/topics';
}
}