ShsCacheableJsonResponse.php in Simple hierarchical select 2.0.x
File
src/Cache/ShsCacheableJsonResponse.php
View source
<?php
namespace Drupal\shs\Cache;
use Drupal\Core\Cache\CacheableJsonResponse;
class ShsCacheableJsonResponse extends CacheableJsonResponse {
protected $context;
public function __construct($context, $data = NULL, $status = 200, $headers = []) {
parent::__construct($data, $status, $headers);
$this->context = $context;
$this->context['encodingOptions'] = $this->encodingOptions;
}
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);
}
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",
];
\Drupal::moduleHandler()
->alter($hooks, $this->content, $this->context);
echo $this->content;
return $this;
}
}