Commit c68d3238 authored by Oleksandr Horbatiuk's avatar Oleksandr Horbatiuk 🧩
Browse files

Issue #3256927 by chmez: Restore the original order of join methods in the...

Issue #3256927 by chmez: Restore the original order of join methods in the field for selecting the allowed method on the course creation/edit page
parent fac2f803
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
                "Issue #2903964: Nesting Paragraph into a IEF then translating makes Paragraph field disappear": "https://www.drupal.org/files/issues/2020-01-23/enable-translatable-references-2903964-23.patch"
            },
            "drupal/social": {
                "Make join methods for groups re-usable": "https://www.drupal.org/files/issues/2022-06-03/social-re-use-group-join-methods-3254715-22.patch"
                "Make join methods for groups re-usable": "https://github.com/goalgorilla/open_social/pull/2658.diff"
            }
        }
    }
+0 −13
Original line number Diff line number Diff line
@@ -7,19 +7,6 @@

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_social_group_join_method_usage().
 */
function social_course_advanced_request_social_group_join_method_usage(): array {
  return [
    [
      'entity_type' => 'group',
      'bundle' => 'course_advanced',
      'field' => 'field_group_allowed_join_method',
    ],
  ];
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
+0 −13
Original line number Diff line number Diff line
@@ -7,19 +7,6 @@

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_social_group_join_method_usage().
 */
function social_course_basic_request_social_group_join_method_usage(): array {
  return [
    [
      'entity_type' => 'group',
      'bundle' => 'course_basic',
      'field' => 'field_group_allowed_join_method',
    ],
  ];
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
+43 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityFormInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
@@ -803,6 +804,48 @@ function social_course_change_form_field_texts(array &$form): void {
  }
}

/**
 * Implements hook_social_group_join_method_info_alter().
 */
function social_course_social_group_join_method_info_alter(
  array &$items,
  ?FieldableEntityInterface $entity
): void {
  if (
    $entity !== NULL &&
    $entity->getEntityTypeId() === 'group' &&
    in_array($type = $entity->bundle(), ['course_basic', 'course_advanced']) &&
    \Drupal::moduleHandler()->moduleExists("social_{$type}_request")
  ) {
    $weight = $items['added']['weight'];
    $items['added']['weight'] = $items['request']['weight'];
    $items['request']['weight'] = $weight;
  }
}

/**
 * Implements hook_social_group_join_method_usage().
 */
function social_course_social_group_join_method_usage(): array {
  $items = $types = [];

  foreach (['course_basic', 'course_advanced'] as $type) {
    if (\Drupal::moduleHandler()->moduleExists("social_{$type}_request")) {
      $types[] = $type;
    }
  }

  if (!empty($types)) {
    $items[] = [
      'entity_type' => 'group',
      'bundle' => $types,
      'field' => 'field_group_allowed_join_method',
    ];
  }

  return $items;
}

/**
 * Implements hook_social_group_types_alter().
 */