protected function MediaForm::actions in Media entity 8
File
- src/
MediaForm.php, line 82
Class
- MediaForm
- Form controller for the media edit forms.
Namespace
Drupal\media_entityCode
protected function actions(array $form, FormStateInterface $form_state) {
$element = parent::actions($form, $form_state);
$media = $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 ($media
->isNew()) {
$element['publish']['#value'] = $this
->t('Save and publish');
}
else {
$element['publish']['#value'] = $media
->isPublished() ? $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 ($media
->isNew()) {
$element['unpublish']['#value'] = $this
->t('Save as unpublished');
}
else {
$element['unpublish']['#value'] = !$media
->isPublished() ? $this
->t('Save and keep unpublished') : $this
->t('Save and unpublish');
}
$element['unpublish']['#weight'] = 10;
// If already published, the 'publish' button is primary.
if ($media
->isPublished()) {
unset($element['unpublish']['#button_type']);
}
else {
unset($element['publish']['#button_type']);
$element['unpublish']['#weight'] = -10;
}
// Remove the "Save" button.
$element['submit']['#access'] = FALSE;
$element['delete']['#access'] = $media
->access('delete');
$element['delete']['#weight'] = 100;
return $element;
}