diff --git a/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php b/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php index a07da59..e415a5d 100644 --- a/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php +++ b/core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php @@ -39,7 +39,7 @@ public function testFormsWithOverrides() { $this->writeSettings($settings); // Test that the overridden label is loaded with the entity. - $this->assertEqual(config_test_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'); @@ -67,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(config_test_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/config_test.module b/core/modules/config/tests/config_test/config_test.module index d7742d0..441c4c6 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -11,16 +11,6 @@ require_once dirname(__FILE__) . '/config_test.hooks.inc'; /** - * Loads a ConfigTest object. - * - * @param string $id - * The ID of the ConfigTest object to load. - */ -function config_test_load($id) { - return entity_load('config_test', $id); -} - -/** * Implements hook_cache_flush(). */ function config_test_cache_flush() { diff --git a/core/modules/config/tests/config_test/src/ConfigTestForm.php b/core/modules/config/tests/config_test/src/ConfigTestForm.php index 56195e2..ef15d30 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' => 'config_test_load', + 'exists' => [get_class($this), 'exists'], 'replace_pattern' => '[^a-z0-9_.]+', ), ); @@ -142,4 +142,25 @@ 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::entityQuery($entity->getEntityTypeId()) + ->condition($entity->getEntityType()->getKey('id'), $entity_id) + ->execute(); + } + } diff --git a/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php index a2f6a6c..a87f4f3 100644 --- a/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationOverviewTest.php @@ -135,7 +135,7 @@ public function testListingPageWithOverrides() { $this->writeSettings($settings); // Test that the overridden label is loaded with the entity. - $this->assertEqual(config_test_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');