You are here

public function ShsCacheableJsonResponse::setData in Simple hierarchical select 8

Same name and namespace in other branches
  1. 2.0.x src/Cache/ShsCacheableJsonResponse.php \Drupal\shs\Cache\ShsCacheableJsonResponse::setData()

Parameters

mixed $data: Data to send as JsonResponse.

bool $alterable: TRUE if the data should be alterable by other modules.

File

src/Cache/ShsCacheableJsonResponse.php, line 37

Class

ShsCacheableJsonResponse
A cacheable JsonResponse that returns alterable data for SHS.

Namespace

Drupal\shs\Cache

Code

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);
}