/** * Overrides \RestfulEntityBase::publicFieldsInfo(). */ public function publicFieldsInfo() { $public_fields = parent::publicFieldsInfo(); $public_fields['acronym'] = array( 'property' => 'field_acronym', ); $public_fields['homepage'] = array( 'property' => 'field_website', 'sub_property' => 'url', ); $public_fields['fts_id'] = array( 'property' => 'field_organization_fts', ); $public_fields['type'] = array( 'property' => 'field_organization_type', 'resource' => array( 'hr_organization_type' => 'organization_types', ), ); return $public_fields; }
/** * Overrides \RestfulEntityBase::publicFieldsInfo(). */ public function publicFieldsInfo() { $public_fields = parent::publicFieldsInfo(); $public_fields['pcode'] = array( 'property' => 'field_pcode', ); $public_fields['iso3'] = array( 'property' => 'field_iso3', ); $public_fields['parents'] = array( 'callback' => array($this, 'getParents'), ); $public_fields['admin_level'] = array( 'property' => 'field_loc_admin_level', ); $public_fields['geolocation'] = array( 'callback' => array($this, 'getGeolocation'), ); $public_fields['parent'] = array( 'property' => 'parent', 'resource' => array( 'hr_location' => 'locations', ), 'process_callbacks' => array(array($this, 'getEntity')), ); return $public_fields; }
/** * Overrides \RestfulEntityBase::publicFieldsInfo(). */ public function publicFieldsInfo() { $public_fields = parent::publicFieldsInfo(); $public_fields['humanitarian_access'] = array( 'property' => 'field_org_type_access', ); return $public_fields; }
/** * {@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); }