diff --git a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php index adafcc79000..4b5b3ca6e65 100644 --- a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php +++ b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php @@ -13,6 +13,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\field\Entity\FieldConfig; use Drupal\field_ui\FieldUI; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Provides a form for the "field storage" edit page. @@ -33,6 +34,9 @@ class FieldStorageConfigEditForm extends EntityForm { // The URL of this entity form contains only the ID of the field_config // but we are actually editing a field_storage_config entity. $field_config = FieldConfig::load($route_match->getRawParameter('field_config')); + if (!$field_config) { + throw new NotFoundHttpException(); + } return $field_config->getFieldStorageDefinition(); } diff --git a/core/modules/field_ui/src/Tests/ManageFieldsTest.php b/core/modules/field_ui/src/Tests/ManageFieldsTest.php index c09550f9eb5..c5ac701acf0 100644 --- a/core/modules/field_ui/src/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php @@ -718,4 +718,17 @@ class ManageFieldsTest extends WebTestBase { $this->assertEqual($view_display->getComponent('field_test_custom_options')['type'], 'field_test_multiple'); } + /** + * Tests the access to non-existent field URLs. + */ + public function testNonExistentFieldUrls() { + $field_id = 'node.foo.bar'; + + $this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/' . $field_id); + $this->assertResponse(404); + + $this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/' . $field_id . '/storage'); + $this->assertResponse(404); + } + }