I have a custom controller that expects POST data. I had it working fine in 8.1.0 retrieving the data using \Drupal::request()->request->all()
and \Drupal::request()->request->get($myvar)
.
Now, without any changes in my custom module, \Drupal::request()->request->all()
is returning an empty array, and \Drupal::request()->request->get($myvar)
is returning NULL
.
Between the time it was working and when the issue arose, my hosting service Pantheon updated their Drupal 8 version from 8.1.0 to 8.1.1 and then 8.1.2. I suspect something may have changed then that affected this.
How can I fix this?
EDIT: Thanks for the comments, still not quite working...
Route YAML:
mymodule.foobar:
path: '/foobar'
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\mymodule\Controller\FooBarController::foobar'
_title: 'foobar'
requirements:
_user_is_logged_in: 'TRUE'
_permission: 'administer site configuration'
Controller:
<?php
namespace Drupal\mymodule\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
/**
* Class FooBarController.
*
* @package Drupal\mymodule\Controller
*/
class FooBarController extends ControllerBase {
/**
* Provides content for the /mymodule/foobar path.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request
*/
public function foobar(Request $request) {
$content = $request->getContent();
$data = array();
$data['a'] = $request->get('foo');
$data['b'] = $request->request->get('foo');
$data['c'] = \Drupal::requestStack()->getCurrentRequest()->request->get('foo');
$data['e'] = $request->request->all();
$data['f'] = $content;
$request = \Drupal::requestStack()->getCurrentRequest();
$content = $request->getContent();
$data['g'] = $request->get('foo');
$data['h'] = $request->request->get('foo');
$data['j'] = $request->request->all();
$data['k'] = $content;
return new JsonResponse((object) $data);
}
}
Note: This was working before with this exact code, correctly using basic HTTP authentication. There have been no changes other than these variations to my controller, and core updates.
Any more ideas?