Skip to content

Instantly share code, notes, and snippets.

@stovak
Created April 18, 2018 17:59
Show Gist options
  • Save stovak/18ce6e730e815a8fab87c03fbdb087ff to your computer and use it in GitHub Desktop.
Save stovak/18ce6e730e815a8fab87c03fbdb087ff to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Drupal\knowledge_center\Plugin\rest\resource\Categories__1_0
*/
namespace Drupal\knowledge_center\Plugin\rest\resource;
use Drupal\knowledge_center\utility\RMRestResponse;
use Drupal\openapi\OpenApiGenerator\RestInspectionTrait;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\knowledge_center\PublicFieldMappers\RMNodeListFieldMapper;
use Drupal\knowledge_center\ListBuilders\RMSubqueueListBuilder;
/**
* Exported content type TEAM MEMBER.
*
* @class Article
*
* @RestResource(
* id = "Categories",
* label = @Translation("Categories"),
* uri_paths = {
* "canonical" = "/api/v1.0/categories/{taxonomy_term}"
* }
* )
*/
class Categories__1_0 extends RMResourceBase {
public function get($term) {
$tax_machine_name = str_replace('-', "_", $term);
$list = new RMSubqueueListBuilder($tax_machine_name);
$list->limitCategory($tax_machine_name, "blog_categories");
$mapper = new RMNodeListFieldMapper($list->getItems(), $this->getVersion());
return new RMRestResponse($mapper->toArray());
}
public function options() {
return new RMRestResponse($this->getResourceConfigs());
}
}
<?php
/**
* @file
* Drupal\knowledge_center\Plugin\rest\resource\RMResourceBase
*/
namespace Drupal\knowledge_center\Plugin\rest\resource;
use Drupal\rest\Plugin\ResourceBase;
abstract class RMResourceBase extends ResourceBase {
static $MAJOR_VERSION = "1";
static $MINOR_VERSION = "0";
function getVersion() {
return sprintf("v%d.%d", self::$MAJOR_VERSION, self::$MINOR_VERSION);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment