114 lines
3.1 KiB
PHP
114 lines
3.1 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Drupal\materio_flag\Controller;
|
||
|
|
||
|
use Drupal\Core\Controller\ControllerBase;
|
||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||
|
// use Drupal\Core\Entity\EntityManagerInterface;
|
||
|
// use Drupal\language\ConfigurableLanguageManagerInterface;
|
||
|
// use Drupal\Core\Render\RendererInterface;
|
||
|
// use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||
|
// use Drupal\Core\Cache\CacheableJsonResponse;
|
||
|
// use Drupal\Core\Cache\CacheableMetadata;
|
||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||
|
// use Drupal\Core\Url;
|
||
|
// use Drupal\core\render\RenderContext;
|
||
|
use Drupal\flag_lists\FlagListsService;
|
||
|
|
||
|
/**
|
||
|
* Class AjaxHomeController.
|
||
|
*/
|
||
|
class MaterioFlagController extends ControllerBase {
|
||
|
|
||
|
/**
|
||
|
* Drupal\Core\Entity\EntityManagerInterface definition.
|
||
|
*
|
||
|
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||
|
*/
|
||
|
// protected $entityManager;
|
||
|
/**
|
||
|
* Drupal\language\ConfigurableLanguageManagerInterface definition.
|
||
|
*
|
||
|
* @var \Drupal\language\ConfigurableLanguageManagerInterface
|
||
|
*/
|
||
|
// protected $languageManager;
|
||
|
/**
|
||
|
* Drupal\Core\Render\RendererInterface definition.
|
||
|
*
|
||
|
* @var \Drupal\Core\Render\RendererInterface
|
||
|
*/
|
||
|
// protected $renderer;
|
||
|
/**
|
||
|
* Drupal\Core\Render\RendererInterface definition.
|
||
|
*
|
||
|
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||
|
*/
|
||
|
// protected $entityTypeManager;
|
||
|
|
||
|
/**
|
||
|
* Drupal\Core\Render\RendererInterface definition.
|
||
|
*
|
||
|
* @var \Drupal\flag_lists\FlagListsService
|
||
|
*/
|
||
|
protected $flaglists;
|
||
|
|
||
|
/**
|
||
|
* Constructs a new AjaxHomeController object.
|
||
|
*/
|
||
|
// public function __construct(EntityManagerInterface $entity_manager, ConfigurableLanguageManagerInterface $language_manager, RendererInterface $renderer, EntityTypeManagerInterface $entity_type_manager) {
|
||
|
// $this->entityManager = $entity_manager;
|
||
|
// $this->languageManager = $language_manager;
|
||
|
// $this->renderer = $renderer;
|
||
|
// $this->entityTypeManager = $entity_type_manager;
|
||
|
// }
|
||
|
public function __construct(FlagListsService $flag_lists_service ) {
|
||
|
$this->flaglists = $flag_lists_service;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* {@inheritdoc}
|
||
|
*/
|
||
|
public static function create(ContainerInterface $container) {
|
||
|
return new static(
|
||
|
$container->get('flaglists'),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Hello.
|
||
|
*
|
||
|
* @return string
|
||
|
* Return Hello string.
|
||
|
*/
|
||
|
public function getUsersFlaggingCollections() {
|
||
|
|
||
|
// $data['data'] = ['test', 'hello'];
|
||
|
|
||
|
// $data['data'] = $this->flaglists->getUsersFlaggingCollections();
|
||
|
|
||
|
// $data['#cache'] = [
|
||
|
// // 'max-age' => \Drupal\Core\Cache\Cache::PERMANENT,
|
||
|
// 'tags' => ['materio-flag-cache'],
|
||
|
// // 'contexts' => [
|
||
|
// // 'languages:language_content'
|
||
|
// // ]
|
||
|
// ];
|
||
|
// $response = new CacheableJsonResponse($data);
|
||
|
// $response->addCacheableDependency(CacheableMetadata::createFromRenderArray($data));
|
||
|
// return $response;
|
||
|
|
||
|
$colls = $this->flaglists->getUsersFlaggingCollections();
|
||
|
|
||
|
$data = [];
|
||
|
foreach ($colls as $id => $collection) {
|
||
|
$data[] = array(
|
||
|
"id" => $id,
|
||
|
"name" => $collection->getName()
|
||
|
);
|
||
|
}
|
||
|
|
||
|
return new JsonResponse($data);
|
||
|
}
|
||
|
|
||
|
}
|