|
@@ -4,66 +4,27 @@ 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\Core\Session\AccountProxy;
|
|
|
+use Drupal\Core\Session\AccountProxyInterface;
|
|
|
use Drupal\flag_lists\FlagListsService;
|
|
|
-
|
|
|
+use Drupal\flag_lists\Entity\FlaggingCollection;
|
|
|
+use Symfony\Component\HttpFoundation\Request;
|
|
|
+use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
/**
|
|
|
* 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.
|
|
|
+ * @var \Drupal\user\User
|
|
|
*/
|
|
|
- // 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;
|
|
|
- }
|
|
|
+ protected $user;
|
|
|
|
|
|
/**
|
|
|
* {@inheritdoc}
|
|
@@ -71,9 +32,18 @@ class MaterioFlagController extends ControllerBase {
|
|
|
public static function create(ContainerInterface $container) {
|
|
|
return new static(
|
|
|
$container->get('flaglists'),
|
|
|
+ $container->get('current_user')
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Constructs a new MaterioFlagController object.
|
|
|
+ */
|
|
|
+ public function __construct(FlagListsService $flag_lists_service, AccountProxyInterface $account) {
|
|
|
+ $this->flaglists = $flag_lists_service;
|
|
|
+ $this->user = $account;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Hello.
|
|
|
*
|
|
@@ -82,21 +52,6 @@ class MaterioFlagController extends ControllerBase {
|
|
|
*/
|
|
|
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 = [];
|
|
@@ -110,4 +65,28 @@ class MaterioFlagController extends ControllerBase {
|
|
|
return new JsonResponse($data);
|
|
|
}
|
|
|
|
|
|
+ public function createUserFlaggingCollection(Request $request) {
|
|
|
+ // dpm($request);
|
|
|
+ $post_data = json_decode( $request->getContent(),TRUE);
|
|
|
+ $name = $post_data['name'];
|
|
|
+
|
|
|
+ $newFlagColl = FlaggingCollection::Create([
|
|
|
+ 'type' => 'flagging_collection_type',
|
|
|
+ 'name' => $name,
|
|
|
+ 'user_id' => $this->user->id(),
|
|
|
+ 'templateflag' => 'dossier'
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $newFlagColl->save();
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'status' => $newFlagColl->get('status')->value,
|
|
|
+ 'id' => $newFlagColl->id(),
|
|
|
+ 'name' => $newFlagColl->getName(),
|
|
|
+ 'newflagcoll_toarray' => $newFlagColl->toArray()
|
|
|
+ ];
|
|
|
+ return new JsonResponse($data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|