class ShsCacheableJsonResponse in Simple hierarchical select 8
Same name and namespace in other branches
- 2.0.x src/Cache/ShsCacheableJsonResponse.php \Drupal\shs\Cache\ShsCacheableJsonResponse
A cacheable JsonResponse that returns alterable data for SHS.
Hierarchy
- class \Drupal\Core\Cache\CacheableJsonResponse extends \Symfony\Component\HttpFoundation\JsonResponse implements CacheableResponseInterface uses CacheableResponseTrait
- class \Drupal\shs\Cache\ShsCacheableJsonResponse
Expanded class hierarchy of ShsCacheableJsonResponse
1 file declares its use of ShsCacheableJsonResponse
- ShsController.php in src/
Controller/ ShsController.php
File
- src/
Cache/ ShsCacheableJsonResponse.php, line 10
Namespace
Drupal\shs\CacheView source
class ShsCacheableJsonResponse extends CacheableJsonResponse {
/**
* Response context used to alter the response data.
*
* @var array
* Array container the field identifier and the bundle.
*/
protected $context;
/**
* {@inheritdoc}
*/
public function __construct($context, $data = NULL, $status = 200, $headers = []) {
parent::__construct($data, $status, $headers);
$this->context = $context;
$this->context['encodingOptions'] = $this->encodingOptions;
}
/**
* {@inheritdoc}
*
* @param mixed $data
* Data to send as JsonResponse.
* @param bool $alterable
* TRUE if the data should be alterable by other modules.
*/
public function setData($data = [], $alterable = FALSE) {
if ($alterable === TRUE) {
$identifier = str_replace('-', '_', $this->context['identifier']);
$hooks = [
'shs_term_data',
"shs__bundle_{$this->context['bundle']}__term_data",
"shs__field_{$identifier}__term_data",
];
\Drupal::moduleHandler()
->alter($hooks, $data, $this->context);
}
parent::setData($data);
}
/**
* {@inheritdoc}
*/
public function sendContent() {
$identifier = str_replace('-', '_', $this->context['identifier']);
$hooks = [
'shs_term_data_response',
"shs__bundle_{$this->context['bundle']}__term_data_response",
"shs__field_{$identifier}__term_data_response",
];
// Alter json encoded data.
\Drupal::moduleHandler()
->alter($hooks, $this->content, $this->context);
echo $this->content;
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableResponseTrait:: |
protected | property | The cacheability metadata. | |
CacheableResponseTrait:: |
public | function | ||
CacheableResponseTrait:: |
public | function | ||
ShsCacheableJsonResponse:: |
protected | property | Response context used to alter the response data. | |
ShsCacheableJsonResponse:: |
public | function | Sends content for the current web response. | |
ShsCacheableJsonResponse:: |
public | function | ||
ShsCacheableJsonResponse:: |
public | function | Constructor. |