- Issue created by @heikkiy
I am trying to solve a problem where a user with limited user permissions cannot replace a media image.
We can do the operation with the Administrator role but when we try to replace the image with a limited user role, we end up in the Path guard route validation and it returns an error and the image is impossible to be replaced.
Here is the stacktrace:
Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException</em>: The file "/tmp/phpW2AbCR" does not exist in <em class="placeholder">Symfony\Component\HttpFoundation\File\File->__construct()</em> (line <em class="placeholder">36</em> of <em class="placeholder">/var/www/html/vendor/symfony/http-foundation/File/File.php</em>). <pre class="backtrace">Symfony\Component\HttpFoundation\File\UploadedFile->__construct('/tmp/phpW2AbCR', 'dhl.png', 'image/png', 0, ) (Line: 86)
Symfony\Component\HttpFoundation\FileBag->convertFileInformation(Array) (Line: 89)
Symfony\Component\HttpFoundation\FileBag->Symfony\Component\HttpFoundation\{closure}(Array)
array_map(Object, Array) (Line: 89)
Symfony\Component\HttpFoundation\FileBag->convertFileInformation(Array) (Line: 52)
Symfony\Component\HttpFoundation\FileBag->set('files', Array) (Line: 61)
Symfony\Component\HttpFoundation\FileBag->add(Array) (Line: 40)
Symfony\Component\HttpFoundation\FileBag->replace(Array) (Line: 31)
Symfony\Component\HttpFoundation\FileBag->__construct(Array) (Line: 269)
Symfony\Component\HttpFoundation\Request->initialize(Array, Array, Array, Array, Array, Array, NULL) (Line: 247)
Symfony\Component\HttpFoundation\Request->__construct(Array, Array, Array, Array, Array, Array, NULL) (Line: 65)
Drupal\Core\Http\TrustedHostsRequestFactory->createRequest(Array, Array, Array, Array, Array, Array, NULL) (Line: 1969)
Symfony\Component\HttpFoundation\Request::createRequestFromFactory(Array, Array, Array, Array, Array, Array) (Line: 293)
Symfony\Component\HttpFoundation\Request::createFromGlobals() (Line: 151)
Drupal\Core\Routing\AccessAwareRouter->match('/media/3091') (Line: 161)
Drupal\Core\Path\PathValidator->getPathAttributes('/media/3091', Object, 1) (Line: 122)
Drupal\Core\Path\PathValidator->getUrl('image/second-test', 1) (Line: 82)
Drupal\Core\Path\PathValidator->getUrlIfValid('/image/second-test') (Line: 62)
Drupal\path_guard\Plugin\Validation\Constraint\ExistingPathValidator->validate(Object, Object) (Line: 201)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateConstraints(Object, '0000000016466abf0000000068f2a272', Array) (Line: 153)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode(Object) (Line: 163)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode(Object) (Line: 163)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validateNode(Object, Array, 1) (Line: 105)
Drupal\Core\TypedData\Validation\RecursiveContextualValidator->validate(Object, NULL, NULL) (Line: 93)
Drupal\Core\TypedData\Validation\RecursiveValidator->validate(Object) (Line: 132)
Drupal\Core\TypedData\TypedData->validate() (Line: 489)
Drupal\Core\Entity\ContentEntityBase->validate() (Line: 419)
Drupal\media\Entity\Media->validate() (Line: 188)
Drupal\Core\Entity\ContentEntityForm->validateForm(Array, Object)
call_user_func_array(Array, Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 275)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'media_image_edit_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('media_image_edit_form', Array, Object) (Line: 591)
Drupal\Core\Form\FormBuilder->processForm('media_image_edit_form', Array, Object) (Line: 323)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 713)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
The error related to Path guard is:
Drupal\path_guard\Plugin\Validation\Constraint\ExistingPathValidator->validate(Object, Object) (Line: 201)
The problem is fixed if I disable Path guard.
I debugged the problem a bit and it seems like the path it's trying to validate is /image/image-name.
1. Enable Path guard module.
2. Create a limited user role which cannot do all the operations in the site.
3. Upload a media image.
4. Edit the media image and try to replace the image.
Active
Code