Commit 70241d32 authored by Oleksandr Horbatiuk's avatar Oleksandr Horbatiuk 🧩
Browse files

Issue #3256927 by chmez: Ensure that the fieldset has a tooltip before modifying the second one

parent 5e043da1
Loading
Loading
Loading
Loading
+34 −16
Original line number Diff line number Diff line
@@ -863,8 +863,21 @@ function social_course_form_node_form_alter(array &$form, FormStateInterface $fo
function social_course_preprocess_fieldset(array &$variables): void {
  // We modify tooltips here using hook function from
  // "social_group_flexible_group" module as it returns what we need.
  /** @var \Drupal\social_course\CourseWrapper $course_wrapper */
  if (
    empty(($element = $variables['element'])['#field_name']) ||
    !in_array($element['#field_name'], [
      'field_flexible_group_visibility',
      'field_group_allowed_visibility',
      'field_group_allowed_join_method',
      'field_content_visibility',
    ])
  ) {
    return;
  }

  /** @var \Drupal\social_course\CourseWrapperInterface $course_wrapper */
  $course_wrapper = \Drupal::service('social_course.course_wrapper');

  $bundles = $course_wrapper->getAvailableBundles();

  if ($group_type = \Drupal::routeMatch()->getRawParameter('group_type')) {
@@ -879,22 +892,27 @@ function social_course_preprocess_fieldset(array &$variables): void {
    }
  }

  $element = $variables['element'];
  if (!empty($element['#field_name'])) {
    if (in_array($element['#field_name'], [
      'field_flexible_group_visibility',
      'field_group_allowed_visibility',
      'field_group_allowed_join_method',
      'field_content_visibility',
    ])) {
  social_group_flexible_group_preprocess_fieldset($variables);
      $toggle_title = $variables['popover']['toggle']['#attributes']['data-title'];
      $variables['popover']['toggle']['#attributes']['data-title'] =
        str_replace(t('Group')->render(), t('Course')->render(), $toggle_title);
      $description_markup =& $variables['popover']['requirements']['descriptions']['#markup'];
      $description_markup = str_replace([t('Group')->render(), t('group')->render()], [t('Course')->render(), t('course')->render()], $description_markup);
    }

  if (!isset($variables['popover'])) {
    return;
  }

  $old = [
    t('Group')->render(),
    t('group')->render(),
  ];

  $new = [
    t('Course')->render(),
    t('course')->render(),
  ];

  $title = &$variables['popover']['toggle']['#attributes']['data-title'];
  $title = str_replace($old[0], $new[0], $title);

  $description = &$variables['popover']['requirements']['descriptions']['#markup'];
  $description = str_replace($old, $new, $description);
}

/**