0

Am using drupal 7 site,am using a callback function to get the nodes list tagged to the particular tid, the process is if i gave the tid value 25 it must return the nodes list which are tagged to this tid.As far this it is working fine.I wish to give the tid as multiple values ie as an array value, the thing am expecting is , if I give 25,17,28 (these are tid values) the result must be the nodes tagged to these tid's .Below is my function

'actions' => array(
        'selectNodes' => array(
          'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/taxonomy_resource'),
          'help'   => t('Returns all nodes with provided taxonomy id.'),
          'access arguments' => array('access content'),
          'callback' => 'taxonomy_service_select_nodes',
          'args'     => array( 
            array(
              'name'         => 'tid',
              'type'         => 'string',
              'description'  => t('The vocabulary ids to retrieve, separated by comma.'),
              'source'       => array('data' => 'tid'),
              'optional'     => FALSE,
            ),
            array(
              'name'         => 'pager',
              'type'         => 'int',
              'description'  => t('Whether the nodes are to be used with a pager (the case on most Drupal pages) or not (in an XML feed, for example).'),
              'source'       => array('data' => 'pager'),
              'optional'     => TRUE,
              'default value'=> TRUE,
            ),
            array(
              'name'         => 'limit',
              'type'         => 'int',
              'description'  => t('Maximum number of nodes to find.'),
              'source'       => array('data' => 'limit'),
              'optional'     => TRUE,
              'default value'=> FALSE,
            ),
            array(
              'name'         => 'order',
              'type'         => 'int',
              'description'  => t('The order clause for the query that retrieve the nodes.'),
              'source'       => array('data' => 'order'),
              'optional'     => TRUE,
              'default value'=> array('t.sticky' => 'DESC', 't.created' => 'DESC'),
            ),
          ),
        ),
      }

can anyone please tell me how can I pass this tid value as array to the callback function used here?

1
  • which callback function is this? Instead of sharing middle content of function please share the whole function code.
    – Cool
    Commented Nov 29, 2013 at 16:55

1 Answer 1

0

I am sharing here some dummy data with you, it might help you.


{
    "tid": "25,17,28",
    "pager": 1,
    "limit": 5,
    "order": "desc"
}

   array(
                  'name'         => 'order',
                  'type'         => 'string', // it should be string because it can be either ASC or DESC
                  'description'  => t('The order clause for the query that retrieve the nodes.'),
                  'source'       => array('data' => 'order'),
                  'optional'     => TRUE,
                  'default value'=> array('t.sticky' => 'DESC', 't.created' => 'DESC'),
                ),

// Call back function

function taxonomy_service_select_nodes($tid, $pager, $limit, $order) {
  $tid_collection = array();
  $tid_collection = explode(',', $tid); // Here your tids are in array format and you can use in your code accordingly.
  echo $pager;
  echo $limit;
  echo $order;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.