This project is not covered by Drupal’s security advisory policy.

Trigger a views refresh via Nodejs. Requires Nodejs and views. If you can get nodejs_notify working then it's set up correctly.

This is a proof of concept. All config is hard coded and I'm not sure of the performance implications of triggering a simultaneous refresh of many views at once.

To use, modify Drupal\nodejs_views\Routing\NodejsViewsRouteSubscriber for the required views ID and display ID.

 protected function alterRoutes(RouteCollection $collection) {

    if ($route = $collection->get('view.view_id.view_display')) {
      $route->setDefault('_controller', '\Drupal\nodejs_views\Routing\NodejsViewsViewsController::handle');
    }

  }

This adds the JS to the correct page. After that, trigger the refresh based on an event. For example, if the view lists content then you may want to trigger it on content save or presave. For example:

use Drupal\Core\Entity\EntityInterface;

/**
 * Implements hook_entity_presave().
 */
function MY_MODULE_entity_presave(EntityInterface $entity) {

  // Hard coded entity and bundled.
  if (($entity->getEntityTypeId() == 'entity_type') &&
    ($entity->bundle() == 'bundle')) {
    
    $nodejs_views = \Drupal::service('nodejs_views_controller');
    
    $nodejs_views->refreshView('view_id.view_display');

  }
   
}

Project information

Releases