public function BlogapiCommunicator::getCategoryList in Blog API 8
Returns a list of available categories on a content type.
Parameters
$ct: Content type machine name.
$username: Drupal username.
$pass: Drupal password.
Return value
array|object Either an error or an array with categories.
File
- src/
BlogapiCommunicator.php, line 242
Class
- BlogapiCommunicator
- Class BlogapiCommunicator.
Namespace
Drupal\blogapiCode
public function getCategoryList($ct, $username, $pass) {
// Check user authentication.
if (!$this
->authenticate($username, $pass)) {
return $this
->returnXmlError(self::BLOGAPI_XML_ERROR_AUTH);
}
// Check if content type is manageable with blogapi.
if (!$this
->validateBlogId($ct)) {
return $this
->returnXmlError(self::BLOGAPI_XML_ERROR_CT);
}
$categories = [];
$vocabularies = $this
->getCtVocabularies($ct);
if (!empty($vocabularies)) {
foreach ($vocabularies as $vocabulary_machine_name) {
$vocab_manager = $this->entityTypeManager
->getStorage('taxonomy_term');
// Get all the terms from a vocabulary.
$terms = $vocab_manager
->loadTree($vocabulary_machine_name);
foreach ($terms as $term) {
$categories[] = array(
'categoryName' => $term->name,
'categoryId' => $term->tid,
);
}
}
}
return $categories;
}