It's possible to specify a fixed value for a resource argument, but it's a bit fiddly and it produces PHP warnings (#1931080: checkNumberOfArguments() expects 'source' to be set):

        'args' => array(
          array(
            // This is a hardcoded parameter to our callback, which requires
            // a bit of hoop-jumping to work with Services.
            'name' => 'entity_type',
            // We have to set this as optional so the default value gets used.
            // @see RESTServer::getControllerArguments()
            'optional' => TRUE,
            // We don't set the source.
            //'source' => NULL,
            'type' => 'string',
            'description' => 'The entity type this operation is on.',
            // The value we actually want to always pass.
            'default value' => $entity_type,
          ),

It would be a lot better DX if there were a source type 'fixed', which simply always takes the value from 'default value'.

Obviously this probably can't be added to 3.x, as all Service servers would need to work with it so it would be an API change.

Comments

marcingy’s picture

joachim’s picture

Status: Active » Closed (duplicate)

Yup. Sorry for the dup.

joachim’s picture

Issue summary: View changes

updated