1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace Drupal\materio_flag\Controller;
- use Drupal\Core\Controller\ControllerBase;
- use Symfony\Component\DependencyInjection\ContainerInterface;
- 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 {
- /**
- * @var \Drupal\flag_lists\FlagListsService
- */
- protected $flaglists;
- /**
- * @var \Drupal\user\User
- */
- protected $user;
- /**
- * {@inheritdoc}
- */
- 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.
- *
- * @return string
- * Return Hello string.
- */
- public function getUsersFlaggingCollections() {
- $colls = $this->flaglists->getUsersFlaggingCollections();
- $data = [];
- foreach ($colls as $id => $collection) {
- $data[] = array(
- "id" => $id,
- "name" => $collection->getName()
- );
- }
- 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);
- }
- }
|