diff -u b/core/modules/action/src/ActionFormBase.php b/core/modules/action/src/ActionFormBase.php --- b/core/modules/action/src/ActionFormBase.php +++ b/core/modules/action/src/ActionFormBase.php @@ -50,7 +50,7 @@ '#maxlength' => 64, '#description' => $this->t('A unique name for this action. It must only contain lowercase letters, numbers and underscores.'), '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], ), ); $form['plugin'] = array( diff -u b/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php --- b/core/modules/block/src/BlockForm.php +++ b/core/modules/block/src/BlockForm.php @@ -135,7 +135,7 @@ '#description' => $this->t('A unique name for this block instance. Must be alpha-numeric and underscore separated.'), '#default_value' => !$entity->isNew() ? $entity->id() : $this->getUniqueMachineName($entity), '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], 'replace_pattern' => '[^a-z0-9_.]+', 'source' => array('settings', 'label'), ), diff -u b/core/modules/block_content/src/BlockContentTypeForm.php b/core/modules/block_content/src/BlockContentTypeForm.php --- b/core/modules/block_content/src/BlockContentTypeForm.php +++ b/core/modules/block_content/src/BlockContentTypeForm.php @@ -45,7 +45,7 @@ '#type' => 'machine_name', '#default_value' => $block_type->id(), '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], ), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, ); diff -u b/core/modules/comment/src/CommentTypeForm.php b/core/modules/comment/src/CommentTypeForm.php --- b/core/modules/comment/src/CommentTypeForm.php +++ b/core/modules/comment/src/CommentTypeForm.php @@ -87,7 +87,7 @@ '#type' => 'machine_name', '#default_value' => $comment_type->id(), '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], ), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => !$comment_type->isNew(), diff -u b/core/modules/config/tests/config_test/src/ConfigTestForm.php b/core/modules/config/tests/config_test/src/ConfigTestForm.php --- b/core/modules/config/tests/config_test/src/ConfigTestForm.php +++ b/core/modules/config/tests/config_test/src/ConfigTestForm.php @@ -62,7 +62,7 @@ '#default_value' => $entity->id(), '#required' => TRUE, '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], 'replace_pattern' => '[^a-z0-9_.]+', ), ); diff -u b/core/modules/contact/src/ContactFormEditForm.php b/core/modules/contact/src/ContactFormEditForm.php --- b/core/modules/contact/src/ContactFormEditForm.php +++ b/core/modules/contact/src/ContactFormEditForm.php @@ -76,7 +76,7 @@ '#default_value' => $contact_form->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], ), '#disabled' => !$contact_form->isNew(), ); diff -u b/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php b/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php --- b/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php @@ -88,7 +88,7 @@ '#default_value' => $this->entity->id(), '#field_prefix' => $this->entity->isNew() ? $this->entity->getTargetType() . '.' : '', '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], 'replace_pattern' => '[^a-z0-9_.]+', ), ); diff -u b/core/modules/filter/src/FilterFormatFormBase.php b/core/modules/filter/src/FilterFormatFormBase.php --- b/core/modules/filter/src/FilterFormatFormBase.php +++ b/core/modules/filter/src/FilterFormatFormBase.php @@ -67,7 +67,7 @@ '#default_value' => $format->id(), '#maxlength' => 255, '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], 'source' => array('name'), ), '#disabled' => !$format->isNew(), diff -u b/core/modules/image/src/Form/ImageStyleFormBase.php b/core/modules/image/src/Form/ImageStyleFormBase.php --- b/core/modules/image/src/Form/ImageStyleFormBase.php +++ b/core/modules/image/src/Form/ImageStyleFormBase.php @@ -36,7 +36,7 @@ $form['name'] = array( '#type' => 'machine_name', '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], ), '#default_value' => $this->entity->id(), '#required' => TRUE, diff -u b/core/modules/node/src/NodeTypeForm.php b/core/modules/node/src/NodeTypeForm.php --- b/core/modules/node/src/NodeTypeForm.php +++ b/core/modules/node/src/NodeTypeForm.php @@ -83,7 +83,7 @@ '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#disabled' => $type->isLocked(), '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], 'source' => array('name'), ), '#description' => t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores. This name will be used for constructing the URL of the %node-add page, in which underscores will be converted into hyphens.', array( diff -u b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php --- b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php +++ b/core/modules/responsive_image/src/ResponsiveImageStyleForm.php @@ -77,7 +77,7 @@ '#type' => 'machine_name', '#default_value' => $responsive_image_style->id(), '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], 'source' => array('label'), ), '#disabled' => (bool) $responsive_image_style->id() && $this->operation != 'duplicate', diff -u b/core/modules/search/src/Form/SearchPageFormBase.php b/core/modules/search/src/Form/SearchPageFormBase.php --- b/core/modules/search/src/Form/SearchPageFormBase.php +++ b/core/modules/search/src/Form/SearchPageFormBase.php @@ -103,7 +103,7 @@ '#disabled' => !$this->entity->isNew(), '#maxlength' => 64, '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], ), ); $form['path'] = array( diff -u b/core/modules/shortcut/src/Form/SwitchShortcutSet.php b/core/modules/shortcut/src/Form/SwitchShortcutSet.php --- b/core/modules/shortcut/src/Form/SwitchShortcutSet.php +++ b/core/modules/shortcut/src/Form/SwitchShortcutSet.php @@ -7,7 +7,7 @@ namespace Drupal\shortcut\Form; -use Drupal\Core\Form\FormBase; +use Drupal\Core\Entity\ConfigEntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\shortcut\Entity\ShortcutSet; use Drupal\shortcut\ShortcutSetStorageInterface; @@ -17,7 +17,7 @@ /** * Builds the shortcut set switch form. */ -class SwitchShortcutSet extends FormBase { +class SwitchShortcutSet extends ConfigEntityForm { /** * The account the shortcut set is for. @@ -106,7 +106,7 @@ $form['id'] = array( '#type' => 'machine_name', '#machine_name' => array( - 'exists' => ['\Drupal\shortcut\Entity\ShortcutSet', 'load'], + 'exists' => [static::class, 'exists'], 'replace_pattern' => '[^a-z0-9-]+', 'replace' => '-', ), diff -u b/core/modules/shortcut/src/ShortcutSetForm.php b/core/modules/shortcut/src/ShortcutSetForm.php --- b/core/modules/shortcut/src/ShortcutSetForm.php +++ b/core/modules/shortcut/src/ShortcutSetForm.php @@ -32,7 +32,7 @@ $form['id'] = array( '#type' => 'machine_name', '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], 'source' => array('label'), 'replace_pattern' => '[^a-z0-9-]+', 'replace' => '-', diff -u b/core/modules/system/src/Form/DateFormatFormBase.php b/core/modules/system/src/Form/DateFormatFormBase.php --- b/core/modules/system/src/Form/DateFormatFormBase.php +++ b/core/modules/system/src/Form/DateFormatFormBase.php @@ -84,7 +84,7 @@ '#disabled' => !$this->entity->isNew(), '#default_value' => $this->entity->id(), '#machine_name' => array( - 'exists' => array(get_class($this), 'exists'), + 'exists' => array(static::class, 'exists'), 'replace_pattern' =>'([^a-z0-9_]+)|(^custom$)', 'error' => $this->t('The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".'), ), diff -u b/core/modules/taxonomy/src/VocabularyForm.php b/core/modules/taxonomy/src/VocabularyForm.php --- b/core/modules/taxonomy/src/VocabularyForm.php +++ b/core/modules/taxonomy/src/VocabularyForm.php @@ -42,7 +42,7 @@ '#default_value' => $vocabulary->id(), '#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH, '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], 'source' => array('name'), ), ); diff -u b/core/modules/user/src/RoleForm.php b/core/modules/user/src/RoleForm.php --- b/core/modules/user/src/RoleForm.php +++ b/core/modules/user/src/RoleForm.php @@ -37,7 +37,7 @@ '#size' => 30, '#maxlength' => 64, '#machine_name' => array( - 'exists' => [get_class($this), 'exists'], + 'exists' => [static::class, 'exists'], ), ); $form['weight'] = array( only in patch2: unchanged: --- /dev/null +++ b/core/lib/Drupal/Core/Entity/ConfigEntityForm.php @@ -0,0 +1,41 @@ +getFormObject()->getEntity()->getEntityType(); + return (bool) \Drupal::entityQuery($entity_type->id()) + ->condition($entity_type->getKey('id'), $entity_id) + ->execute(); + } + +}