diff --git a/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php b/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php index 95fb9ce..e415a5d 100644 --- a/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php +++ b/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php @@ -7,7 +7,6 @@ namespace Drupal\config\Tests; -use Drupal\config_test\Entity\ConfigTest; use Drupal\simpletest\WebTestBase; /** @@ -40,7 +39,7 @@ public function testFormsWithOverrides() { $this->writeSettings($settings); // Test that the overridden label is loaded with the entity. - $this->assertEqual(ConfigTest::load('dotted.default')->label(), $overridden_label); + $this->assertEqual(entity_load('config_test', 'dotted.default')->label(), $overridden_label); // Test that the original label on the listing page is intact. $this->drupalGet('admin/structure/config_test'); @@ -68,7 +67,7 @@ public function testFormsWithOverrides() { $this->assertIdentical((string) $elements[0]['value'], $edited_label); // Test that the overridden label is still loaded with the entity. - $this->assertEqual(ConfigTest::load('dotted.default')->label(), $overridden_label); + $this->assertEqual(entity_load('config_test', 'dotted.default')->label(), $overridden_label); } } diff --git a/core/modules/config/tests/config_test/src/ConfigTestForm.php b/core/modules/config/tests/config_test/src/ConfigTestForm.php index 3304329..158e39b 100644 --- a/core/modules/config/tests/config_test/src/ConfigTestForm.php +++ b/core/modules/config/tests/config_test/src/ConfigTestForm.php @@ -33,7 +33,7 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $entity->id(), '#required' => TRUE, '#machine_name' => array( - 'exists' => $this->entity->getEntityType()->getClass() . '::load', + 'exists' => [get_class($this), 'exists'], 'replace_pattern' => '[^a-z0-9_.]+', ), ); @@ -142,4 +142,23 @@ public function save(array $form, FormStateInterface $form_state) { $form_state->setRedirectUrl($this->entity->urlInfo('collection')); } + /** + * Determines if the entity already exists. + * + * @param string|int $entity_id + * The entity ID. + * @param array $element + * The form element. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + * + * @return bool + * TRUE if the entity exists, FALSE otherwise. + */ + public static function exists($entity_id, array $element, FormStateInterface $form_state) { + /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */ + $entity = $form_state->getFormObject()->getEntity(); + return (bool) \Drupal::entityManager()->getStorage($entity->getEntityTypeId())->load($entity_id); + } + } diff --git a/core/modules/config/tests/config_test/src/Entity/ConfigQueryTest.php b/core/modules/config/tests/config_test/src/Entity/ConfigQueryTest.php index c734568..022b1f1 100644 --- a/core/modules/config/tests/config_test/src/Entity/ConfigQueryTest.php +++ b/core/modules/config/tests/config_test/src/Entity/ConfigQueryTest.php @@ -21,7 +21,6 @@ * } * }, * config_prefix = "query", - * class = "Drupal\config_test\Entity\ConfigQueryTest", * entity_keys = { * "id" = "id", * "label" = "label" diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php index adda0a6..a87f4f3 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php @@ -8,7 +8,6 @@ namespace Drupal\config_translation\Tests; use Drupal\Component\Utility\SafeMarkup; -use Drupal\config_test\Entity\ConfigTest; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\simpletest\WebTestBase; @@ -136,7 +135,7 @@ public function testListingPageWithOverrides() { $this->writeSettings($settings); // Test that the overridden label is loaded with the entity. - $this->assertEqual(ConfigTest::load('dotted.default')->label(), $overridden_label); + $this->assertEqual(entity_load('config_test', 'dotted.default')->label(), $overridden_label); // Test that the original label on the listing page is intact. $this->drupalGet('admin/config/regional/config-translation/config_test');