FlaggingForm.php in Flag 8.4
File
src/Form/FlaggingForm.php
View source
<?php
namespace Drupal\flag\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\flag\Plugin\ActionLink\FormEntryInterface;
class FlaggingForm extends ContentEntityForm {
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
return $form;
}
public function actions(array $form, FormStateInterface $form_state) {
$actions = parent::actions($form, $form_state);
$flagging = $this
->getEntity();
$flag = $flagging
->getFlag();
$action_link = $flag
->getLinkTypePlugin();
$create_button_text = $this
->t('Create Flagging');
if ($action_link instanceof FormEntryInterface) {
$create_button_text = $action_link
->getCreateButtonText();
}
if ($this->entity
->isNew()) {
$actions['submit']['#value'] = $create_button_text;
}
else {
$update_button_text = $this
->t('Update Flagging');
if ($action_link instanceof FormEntryInterface) {
$update_button_text = $action_link
->getUpdateButtonText();
}
$actions['submit']['#value'] = $update_button_text;
}
if (isset($actions['delete'])) {
unset($actions['delete']['#access']);
$delete_button_text = $this
->t('Delete Flagging');
if ($action_link instanceof FormEntryInterface) {
$delete_button_text = $action_link
->getDeleteButtonText();
}
$actions['delete']['#title'] = $delete_button_text;
$route_params = [
'flag' => $this->entity
->getFlagId(),
'entity_id' => $this->entity
->getFlaggableId(),
'destination' => $this
->getRequest()->request
->get('destination'),
];
$url = Url::fromRoute('flag.field_entry.delete', $route_params);
$actions['delete']['#url'] = $url;
}
return $actions;
}
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$entity
->save();
}
}