You are here

public function ChangeGroupMembershipRole::buildConfigurationForm in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/src/Plugin/Action/ChangeGroupMembershipRole.php \Drupal\social_group\Plugin\Action\ChangeGroupMembershipRole::buildConfigurationForm()
  2. 8.5 modules/social_features/social_group/src/Plugin/Action/ChangeGroupMembershipRole.php \Drupal\social_group\Plugin\Action\ChangeGroupMembershipRole::buildConfigurationForm()
  3. 8.6 modules/social_features/social_group/src/Plugin/Action/ChangeGroupMembershipRole.php \Drupal\social_group\Plugin\Action\ChangeGroupMembershipRole::buildConfigurationForm()
  4. 8.7 modules/social_features/social_group/src/Plugin/Action/ChangeGroupMembershipRole.php \Drupal\social_group\Plugin\Action\ChangeGroupMembershipRole::buildConfigurationForm()
  5. 8.8 modules/social_features/social_group/src/Plugin/Action/ChangeGroupMembershipRole.php \Drupal\social_group\Plugin\Action\ChangeGroupMembershipRole::buildConfigurationForm()
  6. 10.3.x modules/social_features/social_group/src/Plugin/Action/ChangeGroupMembershipRole.php \Drupal\social_group\Plugin\Action\ChangeGroupMembershipRole::buildConfigurationForm()
  7. 10.1.x modules/social_features/social_group/src/Plugin/Action/ChangeGroupMembershipRole.php \Drupal\social_group\Plugin\Action\ChangeGroupMembershipRole::buildConfigurationForm()
  8. 10.2.x modules/social_features/social_group/src/Plugin/Action/ChangeGroupMembershipRole.php \Drupal\social_group\Plugin\Action\ChangeGroupMembershipRole::buildConfigurationForm()

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form: An associative array containing the initial structure of the plugin form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return value

array The form structure.

Overrides PluginFormInterface::buildConfigurationForm

File

modules/social_features/social_group/src/Plugin/Action/ChangeGroupMembershipRole.php, line 137

Class

ChangeGroupMembershipRole
Change group membership role.

Namespace

Drupal\social_group\Plugin\Action

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
  $form['#title'] = $this
    ->formatPlural($this->context['selected_count'], 'Change the role of selected member', 'Change the role of @count selected members');
  $id = $this->routeMatch
    ->getRawParameter('group');

  /** @var \Drupal\group\Entity\GroupTypeInterface $group_type */
  $group_type = $this->storage
    ->load($id)
    ->getGroupType();
  $roles = $group_type
    ->getRoles(FALSE);
  $id = $group_type
    ->getMemberRoleId();
  $roles[$id] = $group_type
    ->getMemberRole();
  $markup = $this
    ->formatPlural($this->context['selected_count'], 'Choose which group roles to assign to the member you selected', 'Choose which group roles to assign to the @count members you selected');
  $form['description'] = [
    '#markup' => $markup,
  ];
  $form_state
    ->set('member_role', $id);

  /** @var \Drupal\group\Entity\GroupRoleInterface $role */
  foreach ($roles as &$role) {
    $role = $role
      ->label();
  }
  $form['role'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Group roles'),
    '#options' => $roles,
    '#default_value' => $id,
  ];
  unset($form['list']);
  $form['actions']['submit']['#value'] = $this
    ->t('Change role');
  $form['actions']['submit']['#attributes']['class'] = [
    'button button--primary js-form-submit form-submit btn js-form-submit btn-raised btn-primary waves-effect waves-btn waves-light',
  ];
  $form['actions']['cancel']['#attributes']['class'] = [
    'button button--danger btn btn-flat waves-effect waves-btn',
  ];
  return $form;
}