Created
April 18, 2018 17:59
-
-
Save stovak/18ce6e730e815a8fab87c03fbdb087ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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