I want to be able to pass a custom object of type FormMode
through a route or any other way.
My custom.routing.yml
file is:
custom.page:
path: '/custom/{model}'
defaults:
_controller: '\Drupal\custom\Controller\CustomController::page'
model: ''
requirements:
_permission: 'administer site configuration'
My FormModel
class looks like:
class FormModel {
public $name;
public $area;
function __construct($name, $area) {
$this->name = $name;
$this->area = $area;
}
I create an instance of the object and use Drupal URL function like shown below:
$model = new FormModel('name', 'area');
Url::fromRoute('custom.page')->setRouteParameters(array('model' => $model));
but Drupal throws an error saying Drupal cannot convert a object to a string which I understand it cant convert object to string.
What would be the best practice to pass a object through a route or pass object created from a form into a controller? I dont want to create an entity as I would then need to update the database with the new fields.
Thanks