/**
  * {@inheritdoc}
  */
 protected function actions(array $form, FormStateInterface $form_state)
 {
     $element = parent::actions($form, $form_state);
     $term = $this->entity;
     // Add a "Publish" button.
     $element['publish'] = $element['submit'];
     // If the "Publish" button is clicked, we want to update the status to
     // "published".
     $element['publish']['#published_status'] = TRUE;
     $element['publish']['#dropbutton'] = 'save';
     if ($term->isNew()) {
         $element['publish']['#value'] = $this->t('Save and publish');
     } else {
         $element['publish']['#value'] = $term->status->value ? $this->t('Save and keep published') : $this->t('Save and publish');
     }
     $element['publish']['#weight'] = 0;
     // Add a "Unpublish" button.
     $element['unpublish'] = $element['submit'];
     // If the "Unpublish" button is clicked, we want to update the status to
     // "unpublished".
     $element['unpublish']['#published_status'] = FALSE;
     $element['unpublish']['#dropbutton'] = 'save';
     if ($term->isNew()) {
         $element['unpublish']['#value'] = $this->t('Save as unpublished');
     } else {
         $element['unpublish']['#value'] = !$term->status->value ? $this->t('Save and keep unpublished') : $this->t('Save and unpublish');
     }
     $element['unpublish']['#weight'] = 10;
     // If already published, the 'publish' button is primary.
     if ($term->status->value) {
         unset($element['unpublish']['#button_type']);
     } else {
         unset($element['publish']['#button_type']);
         $element['unpublish']['#weight'] = -10;
     }
     // Remove the "Save" button.
     $element['submit']['#access'] = FALSE;
     return $element;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 protected function actions(array $form, FormStateInterface $form_state)
 {
     $actions = parent::actions($form, $form_state);
     if (!$this->entity->isNew() && $this->entity->hasLinkTemplate('forum-delete-form')) {
         $actions['delete']['#url'] = $this->entity->urlInfo('forum-delete-form');
     } else {
         unset($actions['delete']);
     }
     return $actions;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 protected function actions(array $form, array &$form_state)
 {
     $actions = parent::actions($form, $form_state);
     if (!$this->entity->isNew() && $this->entity->hasLinkTemplate('forum-delete-form')) {
         $route_info = $this->entity->urlInfo('forum-delete-form');
         $actions['delete']['#options'] = $route_info->getOptions();
         $actions['delete']['#route_name'] = $route_info->getRouteName();
         $actions['delete']['#route_parameters'] = $route_info->getRouteParameters();
     } else {
         unset($actions['delete']);
     }
     return $actions;
 }