AnalyticsController.php in Analytics 8
File
src/Controller/AnalyticsController.php
View source
<?php
namespace Drupal\analytics\Controller;
use Drupal\analytics\Entity\AnalyticsServiceInterface;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
class AnalyticsController extends ControllerBase {
public function ajaxOperation(AnalyticsServiceInterface $analytics_service, $op, Request $request) {
$analytics_service
->{$op}()
->save();
if ($op === 'enable') {
$this
->messenger()
->addMessage($this
->t('Enabled analytics service @label.', [
'@label' => $analytics_service
->label(),
]));
$this
->getLogger('analytics')
->info('Enabled analytics service @label.', [
'@label' => $analytics_service
->label(),
]);
}
elseif ($op === 'disable') {
$this
->messenger()
->addMessage($this
->t('Disabled analytics service @label.', [
'@label' => $analytics_service
->label(),
]));
$this
->getLogger('analytics')
->info('Disabled analytics service @label.', [
'@label' => $analytics_service
->label(),
]);
}
if ($request->request
->get('js')) {
$list = $this
->entityTypeManager()
->getListBuilder('analytics_service')
->render();
$response = new AjaxResponse();
$response
->addCommand(new ReplaceCommand('#analytics-entity-list', $list));
return $response;
}
return $this
->redirect('entity.analytics_service.collection');
}
}