Comments (3)
Did you figure this out? Maybe the answer will help someone else in the future.
from restful.
Hi @e0ipso , I thought that nobody will respond to it, so I've tried to delete the issue, but I could only close it. I've also posted the question on drupal stackexchange, but also no sign of solution yet. After winter holidays, I'll try once more and if I find a solution, I'll post it here.
from restful.
I've resolved the sorting problem with sorting data inside the formatter. Here's my code in case someone had similar problems.
<?php
/**
* @file
* Contains \Drupal\restful\Plugin\formatter\OrderFormatter.
*/
namespace Drupal\my_module\Plugin\formatter;
use Drupal\restful\Plugin\formatter\FormatterJson;
use Drupal\restful\Plugin\formatter\FormatterInterface;
/**
* Class OrderFormatter
* @package Drupal\restful\Plugin\formatter
*
* @Formatter(
* id = "order_formatter",
* label = "ORDER FORMATTER",
* description = "Output filtered data",
* curie = {
* "name": "dis",
* "path": "doc/rels",
* "template": "/{rel}",
* },
* )
*/
class OrderFormatter extends FormatterJson implements FormatterInterface {
/**
* Content Type
*
* @var string
*/
protected $contentType = 'application/json+sort; charset=utf-8';
/**
* {@inheritdoc}
*/
public function render(array $structured_data) {
$i=0;
foreach ($structured_data['data'] as $v) {
$structured_data['data'][$i]['unsortedThings'] = $this->sortBy($structured_data['data'][$i]['unsortedThings']);
$i++;
}
return drupal_json_encode($structured_data);
}
public function sortBy($arr) {
$results = [];
foreach ($arr as $k=>$v) {
$results[$k] = $v['weight']; //this is my sorting field
}
asort($results, SORT_REGULAR);
foreach (array_keys($results) as $key) {
$results[$key] = $arr[$key];
}
$results = array_values($results);
return $results;
}
}
You run this formatter by adding header to your request: Accept: application/json+sort; charset=utf-8
from restful.
Related Issues (20)
- Handling child entity references in the parent
- Adding custom info to the discovery resource
- Duplicate 401 unauthorised error on incorrect access token
- Language and Cache
- Cannot filter != or NOT IN HOT 1
- Item Url gives 404
- Return fields not found in node (but are)
- 1.x "queryForListFilter()" does not support "NOT IN" operator HOT 1
- Affected by SA-CORE-2019-003? HOT 5
- not able to POST comment on node
- token authentication entity query failure HOT 1
- Support Request: Custom Access HOT 3
- Pull security changes from drupal.org HOT 3
- Post new entry in Entity List with Node Reference to other Node HOT 2
- localhost/api/articles 404
- Taxonomy Term in Restful module
- Plugin ID 'json_api' was not found. HOT 1
- Question, authentication for asynchronous requests.
- Not able to update files in API catalog module
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from restful.