class ShortcutSetForm
Same name and namespace in other branches
- 11.x core/modules/shortcut/src/ShortcutSetForm.php \Drupal\shortcut\ShortcutSetForm
Form handler for the shortcut set entity edit forms.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase extends \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm extends \Drupal\Core\Entity\EntityFormInterface implements \Drupal\Core\Form\FormBase
- class \Drupal\Core\Entity\BundleEntityFormBase implements \Drupal\Core\Entity\EntityForm
- class \Drupal\shortcut\ShortcutSetForm implements \Drupal\Core\Entity\BundleEntityFormBase
- class \Drupal\Core\Entity\BundleEntityFormBase implements \Drupal\Core\Entity\EntityForm
- class \Drupal\Core\Entity\EntityForm extends \Drupal\Core\Entity\EntityFormInterface implements \Drupal\Core\Form\FormBase
Expanded class hierarchy of ShortcutSetForm
File
-
core/
modules/ shortcut/ src/ ShortcutSetForm.php, line 13
Namespace
Drupal\shortcutView source
class ShortcutSetForm extends BundleEntityFormBase {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$entity = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Set name'),
'#description' => $this->t('The new set is created by copying links from your default shortcut set.'),
'#required' => TRUE,
'#default_value' => $entity->label(),
];
$form['id'] = [
'#type' => 'machine_name',
'#machine_name' => [
'exists' => '\\Drupal\\shortcut\\Entity\\ShortcutSet::load',
'source' => [
'label',
],
'replace_pattern' => '[^a-z0-9-]+',
'replace' => '-',
],
'#default_value' => $entity->id(),
// This id could be used for menu name.
'#maxlength' => 23,
];
$form['actions']['submit']['#value'] = $this->t('Create new set');
return $this->protectBundleIdElement($form);
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$is_new = !$entity->getOriginalId();
$entity->save();
if ($is_new) {
$this->messenger()
->addStatus($this->t('The %set_name shortcut set has been created. You can edit it from this page.', [
'%set_name' => $entity->label(),
]));
}
else {
$this->messenger()
->addStatus($this->t('Updated set name to %set-name.', [
'%set-name' => $entity->label(),
]));
}
$form_state->setRedirectUrl($this->entity
->toUrl('customize-form'));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.