You are here

class SocialGroupSettings in Open Social 10.1.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
  2. 8 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
  3. 8.2 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
  4. 8.3 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
  5. 8.4 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
  6. 8.5 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
  7. 8.6 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
  8. 8.7 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
  9. 8.8 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
  10. 10.3.x modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
  11. 10.0.x modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
  12. 10.2.x modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings

Settings form which enables site managers to configure different options.

@package Drupal\social_event_managers\Form

Hierarchy

Expanded class hierarchy of SocialGroupSettings

1 string reference to 'SocialGroupSettings'
social_group.routing.yml in modules/social_features/social_group/social_group.routing.yml
modules/social_features/social_group/social_group.routing.yml

File

modules/social_features/social_group/src/Form/SocialGroupSettings.php, line 17

Namespace

Drupal\social_group\Form
View source
class SocialGroupSettings extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'social_group.settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'social_group_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('social_group.settings');
    $form['permissions'] = [
      '#type' => 'checkboxes',
      '#title' => $this
        ->t('Group permissions'),
      '#options' => [
        'allow_group_create' => $this
          ->t('Allow regular users to create new groups'),
        'allow_group_selection_in_node' => $this
          ->t('Allow regular users to change the group their content belong to'),
        'address_visibility_settings' => $this
          ->t('Only show the group address to the group members'),
      ],
      '#weight' => 10,
    ];
    foreach (array_keys($form['permissions']['#options']) as $permission) {
      if ($this
        ->hasPermission($permission)) {
        $form['permissions']['#default_value'][] = $permission;
      }
    }
    $form['default_hero'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Default group hero size'),
      '#description' => $this
        ->t('The default hero size used on this platform. Only applicable when logged-in users cannot choose a different hero size on each group.'),
      '#default_value' => $config
        ->get('default_hero'),
      '#options' => $this
        ->getCropTypes(),
      '#weight' => 20,
    ];

    // Add an option for site manager to enable/disable option to choose group
    // type on page to add flexible groups.
    if (\Drupal::moduleHandler()
      ->moduleExists('social_group_flexible_group')) {
      $form['social_group_type_required'] = [
        '#type' => 'checkbox',
        '#title' => $this
          ->t('Require group types'),
        '#description' => $this
          ->t('When checked, a new option will appear on
          the flexible group form which requires group creators to select a
          group type, this allows for a better categorisation of groups in your
          community. You can add or edit the available group types @link', [
          '@link' => Link::fromTextAndUrl('here.', Url::fromUserInput('/admin/structure/taxonomy/manage/group_type/overview'))
            ->toString(),
        ]),
        '#default_value' => $config
          ->get('social_group_type_required'),
      ];
    }
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);
    $config = $this
      ->config('social_group.settings');
    foreach ($form_state
      ->getValue('permissions') as $key => $value) {
      $config
        ->set($key, !empty($value));
    }
    $config
      ->set('default_hero', $form_state
      ->getValue('default_hero'))
      ->save();
    $config
      ->set('social_group_type_required', $form_state
      ->getValue('social_group_type_required'))
      ->save();
    Cache::invalidateTags([
      'group_view',
    ]);
  }

  /**
   * Function that gets the available crop types.
   *
   * @return array
   *   The croptypes.
   */
  protected function getCropTypes() {
    $croptypes = [
      'hero',
      'hero_small',
    ];
    $options = [];
    foreach ($croptypes as $croptype) {
      $type = CropType::load($croptype);
      if ($type instanceof CropType) {
        $options[$type
          ->id()] = $type
          ->label();
      }
    }
    return $options;
  }

  /**
   * Check if permission is granted.
   *
   * @param string $name
   *   The permission name.
   *
   * @return bool
   *   TRUE if permission is granted.
   */
  protected function hasPermission($name) {
    return !empty($this
      ->config('social_group.settings')
      ->get($name));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigFormBase::create public static function Instantiates a new instance of this class. Overrides FormBase::create 18
ConfigFormBase::__construct public function Constructs a \Drupal\system\ConfigFormBase object. 16
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 72
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
SocialGroupSettings::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
SocialGroupSettings::getCropTypes protected function Function that gets the available crop types.
SocialGroupSettings::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
SocialGroupSettings::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
SocialGroupSettings::hasPermission protected function Check if permission is granted.
SocialGroupSettings::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.