ShortcutForm.php in Drupal 8
File
core/modules/shortcut/src/ShortcutForm.php
View source
<?php
namespace Drupal\shortcut;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
class ShortcutForm extends ContentEntityForm {
protected $entity;
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['#attached']['library'][] = 'core/drupal.form';
return $form;
}
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$status = $entity
->save();
$url = $entity
->getUrl();
if ($url
->access()) {
$view_link = Link::fromTextAndUrl($entity
->getTitle(), $url)
->toString();
}
else {
$view_link = $entity
->getTitle();
}
if ($status == SAVED_UPDATED) {
$message = $this
->t('The shortcut %link has been updated.', [
'%link' => $view_link,
]);
}
else {
$message = $this
->t('Added a shortcut for %title.', [
'%title' => $view_link,
]);
}
$this
->messenger()
->addStatus($message);
$form_state
->setRedirect('entity.shortcut_set.customize_form', [
'shortcut_set' => $entity
->bundle(),
]);
}
}