You are here

protected function GroupForm::actions in Group 8

Same name and namespace in other branches
  1. 2.0.x src/Entity/Form/GroupForm.php \Drupal\group\Entity\Form\GroupForm::actions()

Returns an array of supported actions for the current entity form.

This function generates a list of Form API elements which represent actions supported by the current entity form.

@todo Consider introducing a 'preview' action here, since it is used by many entity types.

Parameters

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array An array of supported Form API action elements keyed by name.

Overrides EntityForm::actions

File

src/Entity/Form/GroupForm.php, line 36

Class

GroupForm
Form controller for the group add and edit forms.

Namespace

Drupal\group\Entity\Form

Code

protected function actions(array $form, FormStateInterface $form_state) {
  $actions = parent::actions($form, $form_state);

  /** @var \Drupal\group\Entity\GroupTypeInterface $group_type */
  $group_type = $this
    ->getEntity()
    ->getGroupType();
  $replace = [
    '@group_type' => $group_type
      ->label(),
  ];

  // We need to adjust the actions when using the group creator wizard.
  if ($this->operation == 'add') {
    if ($form_state
      ->get('group_wizard') && $form_state
      ->get('group_wizard_id') == 'group_creator') {

      // If we are using the group creator wizard, then we should not save the
      // group right away. Instead, we should store the data we have and wait
      // until the end of the wizard to save.
      $actions['submit']['#submit'] = [
        '::submitForm',
        '::store',
      ];

      // Update the label to be more user friendly by indicating that the user
      // needs to go through an extra step to finish the group creation.
      $actions['submit']['#value'] = $this
        ->t('Create @group_type and complete your membership', $replace);

      // Add a cancel button to clear the private temp store. This exits the
      // wizard without saving,
      $actions['cancel'] = [
        '#type' => 'submit',
        '#value' => $this
          ->t('Cancel'),
        '#submit' => [
          '::cancel',
        ],
        '#limit_validation_errors' => [],
      ];
    }
    elseif ($group_type
      ->creatorGetsMembership()) {
      $actions['submit']['#value'] = $this
        ->t('Create @group_type and become a member', $replace);
    }
    else {
      $actions['submit']['#value'] = $this
        ->t('Create @group_type', $replace);
    }
  }
  return $actions;
}