class SocialGroupSettings in Open Social 10.1.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
- 8 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
- 8.2 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
- 8.3 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
- 8.4 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
- 8.5 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
- 8.6 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
- 8.7 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
- 8.8 modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
- 10.3.x modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
- 10.0.x modules/social_features/social_group/src/Form/SocialGroupSettings.php \Drupal\social_group\Form\SocialGroupSettings
- 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
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\social_group\Form\SocialGroupSettings
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
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\FormView 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
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
18 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 16 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
72 |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
SocialGroupSettings:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SocialGroupSettings:: |
protected | function | Function that gets the available crop types. | |
SocialGroupSettings:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SocialGroupSettings:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SocialGroupSettings:: |
protected | function | Check if permission is granted. | |
SocialGroupSettings:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |