You are here

protected function ProfileFormController::actions in Profile 2 8

Overrides Drupal\Core\Entity\EntityForm::actions().

Overrides EntityForm::actions

File

src/ProfileFormController.php, line 33
Contains \Drupal\profile\ProfileFormController.

Class

ProfileFormController
Form controller for profile forms.

Namespace

Drupal\profile

Code

protected function actions(array $form, FormStateInterface $form_state) {
  $element = parent::actions($form, $form_state);
  $profile = $this->entity;
  if (\Drupal::currentUser()
    ->hasPermission('administer profiles')) {

    // Add an "Activate" button.
    $element['activate'] = $element['submit'];
    $element['activate']['#dropbutton'] = 'save';
    if ($profile
      ->isNew()) {
      $element['activate']['#value'] = t('Save and make active');
    }
    else {
      $element['activate']['#value'] = $profile
        ->isActive() ? t('Save and keep active') : t('Save and make active');
    }
    $element['activate']['#weight'] = 0;
    array_unshift($element['activate']['#submit'], array(
      $this,
      'activate',
    ));

    // Add a "Deactivate" button.
    $element['deactivate'] = $element['submit'];
    $element['deactivate']['#dropbutton'] = 'save';
    if ($profile
      ->isNew()) {
      $element['deactivate']['#value'] = t('Save as inactive');
    }
    else {
      $element['deactivate']['#value'] = !$profile
        ->isActive() ? t('Save and keep inactive') : t('Save and make inactive');
    }
    $element['deactivate']['#weight'] = 10;
    array_unshift($element['deactivate']['#submit'], array(
      $this,
      'deactivate',
    ));

    // If already deactivated, the 'activate' button is primary.
    if ($profile
      ->isActive()) {
      unset($element['deactivate']['#button_type']);
    }
    else {
      unset($element['deactivate']['#button_type']);
      $element['deactivate']['#weight'] = -10;
    }

    // Remove the "Save" button.
    $element['submit']['#access'] = FALSE;
  }
  $element['delete']['#access'] = $profile
    ->access('delete');
  $element['delete']['#weight'] = 100;
  return $element;
}