/**
  * {@inheritdoc}
  *
  * Change the bundle on the fly, based on a parameter send in the request.
  * This applies only for the "tags" and "categories" resources.
  */
 public function process($path = '', array $request = array(), $method = \RestfulInterface::GET, $check_rate_limit = TRUE)
 {
     $resource_name = $this->getResourceName();
     if ($resource_name == 'tags' || $resource_name == 'categories') {
         if (empty($request['group']) || !intval($request['group'])) {
             throw new \RestfulBadRequestException('The "group" parameter is missing for the request, thus the vocabulary cannot be set for the group.');
         }
         $node = node_load($request['group']);
         if (!$node) {
             throw new \RestfulBadRequestException('The "group" parameter is not a node.');
         } elseif ($node->type != 'group') {
             throw new \RestfulBadRequestException('The "group" parameter is not a of type "group".');
         }
         $vocab_name = $resource_name == 'tags' ? 'Tags' : 'Categories';
         if (!($og_vocab = c4m_restful_get_og_vocab_by_name('node', $node->nid, $vocab_name))) {
             throw new \RestfulBadRequestException('The "group" does not have a "' . $vocab_name . '" vocabulary.');
         }
         $this->bundle = $og_vocab[0]->machine_name;
         // Group ID removed from the request because it's not a field in the
         // taxonomy.
         unset($request['group']);
     }
     return parent::process($path, $request, $method, $check_rate_limit);
 }
 /**
  * {@inheritdoc}
  *
  * Change the bundle on the fly, based on a parameter send in the request.
  */
 public function process($path = '', array $request = array(), $method = \RestfulInterface::GET, $check_rate_limit = TRUE)
 {
     if (empty($request['account']) || !intval($request['account'])) {
         throw new \RestfulBadRequestException('The "account" parameter is missing for the request, thus the vocabulary cannot be set for the account.');
     }
     // Get the account node.
     $node = node_load($request['account']);
     if (!$node) {
         throw new \RestfulBadRequestException('The "account" parameter is not a node.');
     } elseif ($node->type != 'account') {
         throw new \RestfulBadRequestException('The "account" parameter is not a of type "account".');
     }
     // Get an array of OG vocabularies for the account.
     $og_vocabs = og_vocab_relation_get_by_group('node', $node->nid);
     if (empty($og_vocabs)) {
         throw new \RestfulBadRequestException('No vocabulary is given for the specified account.');
     }
     // Get the meter-category taxonomy
     $found = FALSE;
     foreach ($og_vocabs as $og_vocab) {
         $vocabulary = taxonomy_vocabulary_load($og_vocab->vid);
         if (strpos($vocabulary->machine_name, 'meter_category_') === FALSE) {
             // Not a meter-category vocabulary, skip.
             continue;
         }
         $found = TRUE;
         $taxonomy = taxonomy_vocabulary_load($og_vocab->vid);
         $this->bundle = $taxonomy->machine_name;
         // Loop no more.
         break;
     }
     if (!$found) {
         throw new \RestfulBadRequestException('No meter-category vocabulary was found.');
     }
     // Remove account ID from the request because it's not a field in the taxonomy.
     unset($request['account']);
     return parent::process($path, $request, $method, $check_rate_limit);
 }