You are here

function lightning_api_view_presave in Lightning API 8.4

Same name and namespace in other branches
  1. 8.3 lightning_api.module \lightning_api_view_presave()

Implements hook_ENTITY_TYPE_presave().

1 call to lightning_api_view_presave()
lightning_api_update_8301 in ./lightning_api.install
Disables the content view's "include destination" switch for operations.

File

./lightning_api.module, line 29
Contains hook implementations for Lightning API.

Code

function lightning_api_view_presave(ViewEntityInterface $view) {
  if (Drupal::isConfigSyncing()) {
    return;
  }
  elseif ($view
    ->id() === 'content' && $view
    ->isNew()) {
    $display =& $view
      ->getDisplay('default');

    // If the Operations field's 'Include destination' switch is enabled, it
    // will force every operation to have the 'destination' query parameter,
    // which breaks JSON API 2.0, causing the 'View JSON' operation to throw a
    // BadRequestHttpException.
    if (isset($display['display_options']['fields']['operations']['destination'])) {
      $display['display_options']['fields']['operations']['destination'] = FALSE;
    }
  }
}