You are here

function social_post_form_post_form_alter in Open Social 8.8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_post/social_post.module \social_post_form_post_form_alter()
  2. 8 modules/social_features/social_post/social_post.module \social_post_form_post_form_alter()
  3. 8.2 modules/social_features/social_post/social_post.module \social_post_form_post_form_alter()
  4. 8.3 modules/social_features/social_post/social_post.module \social_post_form_post_form_alter()
  5. 8.4 modules/social_features/social_post/social_post.module \social_post_form_post_form_alter()
  6. 8.5 modules/social_features/social_post/social_post.module \social_post_form_post_form_alter()
  7. 8.6 modules/social_features/social_post/social_post.module \social_post_form_post_form_alter()
  8. 8.7 modules/social_features/social_post/social_post.module \social_post_form_post_form_alter()
  9. 10.3.x modules/social_features/social_post/social_post.module \social_post_form_post_form_alter()
  10. 10.0.x modules/social_features/social_post/social_post.module \social_post_form_post_form_alter()
  11. 10.1.x modules/social_features/social_post/social_post.module \social_post_form_post_form_alter()
  12. 10.2.x modules/social_features/social_post/social_post.module \social_post_form_post_form_alter()

Implements hook_form_FORM_ID_alter().

File

modules/social_features/social_post/social_post.module, line 21
The Social post module.

Code

function social_post_form_post_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  if ($form_state
    ->getFormObject()
    ->getEntity()
    ->isNew()) {

    // Load current user.
    $account = User::load(Drupal::currentUser()
      ->id());

    // Load compact notification view mode of the attached profile.
    if ($account) {
      $storage = \Drupal::entityTypeManager()
        ->getStorage('profile');
      if (!empty($storage)) {
        $user_profile = $storage
          ->loadByUser($account, 'profile');
        if ($user_profile) {
          $content = \Drupal::entityTypeManager()
            ->getViewBuilder('profile')
            ->view($user_profile, 'compact_notification');

          // Add to a new field, so twig can render it.
          $form['current_user_image'] = $content;
        }
      }
    }
  }

  // Reset title display.
  $form['field_post']['widget'][0]['#title_display'] = "";

  // Set submit button caption to Post instead of Save.
  $form['actions']['submit']['#value'] = t('Post', [], [
    'context' => 'Post button',
  ]);
  if (!empty($form['field_post']) && !empty($form['field_post']['widget'][0])) {

    // For posting on the stream on the group stream.
    if (!empty(_social_group_get_current_group())) {
      $form['field_post']['widget'][0]['#placeholder'] = t('Say something to the group');
      $form['field_post']['widget'][0]['#title'] = t('Say something to the group');
    }
    elseif (!empty(\Drupal::routeMatch()
      ->getParameter('user')) && \Drupal::routeMatch()
      ->getParameter('user')
      ->id() != \Drupal::currentUser()
      ->id()) {
      $user_profile = \Drupal::routeMatch()
        ->getParameter('user');
      $name = $user_profile
        ->getDisplayName();
      $form['field_post']['widget'][0]['#placeholder'] = t('Leave a message to @name', [
        '@name' => $name,
      ]);
      $form['field_post']['widget'][0]['#title'] = t('Leave a message to @name', [
        '@name' => $name,
      ]);
    }
    else {
      $title = t('Say something to the Community');
      $form['field_post']['widget'][0]['#title'] = $title;
      $form['field_post']['widget'][0]['#placeholder'] = $title;
    }
  }
}