reinstalled all contribs with composer
need to run : drush ev 'drupal_flush_all_caches();' drush cr and restart nginx and php-fpm before loading the website
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\User\UserDataInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
||||
use Drupal\edlp_studio\Entity\Chutier;
|
||||
|
||||
/**
|
||||
* Class ChutierController.
|
||||
*/
|
||||
class ChutierController extends ControllerBase {
|
||||
|
||||
protected $user;
|
||||
protected $userdata;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct(AccountInterface $account, UserDataInterface $userdata) {
|
||||
$this->user = $account;
|
||||
$this->userdata = $userdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
// Instantiates this form class.
|
||||
return new static(
|
||||
// Load the service required to construct this class.
|
||||
$container->get('current_user'),
|
||||
$container->get('user.data')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* AdddContent.
|
||||
*
|
||||
* @return json
|
||||
* Return status.
|
||||
*/
|
||||
public function AddRemoveContent($action, $id, $cid) {
|
||||
$this->error_message = null;
|
||||
$status = 'ok';
|
||||
// get current user :
|
||||
// done by DependencyInjection of AccountInterface
|
||||
|
||||
// TODO: use the send chutier instead of default
|
||||
// check if default chutier exists ? yes use it : no create and use it.
|
||||
$this->checkChutier();
|
||||
// dpm($this->chutier);
|
||||
|
||||
// check if $id exists, is a document, and does not already exist in chutier
|
||||
switch($action){
|
||||
case 'add':
|
||||
$this->validateNewDoc($id);
|
||||
if(!$this->error_message){
|
||||
// add $id to documents field
|
||||
$this->addNewDoc($id);
|
||||
$message = t('Node @id added to chutier.', array('@id'=>$id));
|
||||
}else{
|
||||
$status = "error";
|
||||
}
|
||||
break;
|
||||
case 'remove':
|
||||
$this->removeDoc($id);
|
||||
$message = t('Node @id removed to chutier.', array('@id'=>$id));
|
||||
break;
|
||||
}
|
||||
|
||||
$url = Chutier::getActionsUrl($id, $this->user->id());
|
||||
$new_link_build = array(
|
||||
'#title' => t("Chutier."),
|
||||
'#type' => 'link',
|
||||
'#url' => $url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $url->getInternalPath()
|
||||
)
|
||||
)
|
||||
);
|
||||
$new_link = render($new_link_build);
|
||||
|
||||
if($status == 'error'){
|
||||
$message = $this->error_message;
|
||||
}
|
||||
|
||||
// JSON
|
||||
$response = new JsonResponse();
|
||||
$data = array(
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
'new_link' => $new_link,
|
||||
'action_done' => $action,
|
||||
);
|
||||
$response->setData($data);
|
||||
return $response;
|
||||
|
||||
// classic html
|
||||
// return array(
|
||||
// '#markup'=>'Status : ' . $status . ' | Message : ' . $message,
|
||||
// );
|
||||
}
|
||||
|
||||
private function addNewDoc($id){
|
||||
$this->chutier->documents->appendItem($id);
|
||||
$this->chutier->save();
|
||||
}
|
||||
|
||||
private function removeDoc($id){
|
||||
$values = array_column($this->chutier->documents->getValue(), 'target_id');
|
||||
$index = array_search($id,$values);
|
||||
$this->chutier->documents->removeItem($index);
|
||||
$this->chutier->save();
|
||||
}
|
||||
|
||||
private function validateNewDoc($id){
|
||||
$node = entity_load('node', $id);
|
||||
if($node){
|
||||
// TODO: get node bundle by settings (@see readme)
|
||||
if($node->getType() == 'enregistrement'){
|
||||
$docs = array_column($this->chutier->documents->getValue(), 'target_id');
|
||||
if( in_array($id, $docs) ){
|
||||
$this->error_message = t("Node '@title'(@id) already exists in chutier '@name'(@cid)", array(
|
||||
'@title'=>$node->getTitle(),
|
||||
'@id'=>$id,
|
||||
'@name' => $this->chutier->getName(),
|
||||
'@cid' => $this->chutier->id())
|
||||
);
|
||||
}
|
||||
}else{
|
||||
$this->error_message = t("Node @title (@id) is not an Enregistrement (@type)", array(
|
||||
'@title'=>$node->getTitle(),
|
||||
'@id'=>$id,
|
||||
'@type' => $node->getType())
|
||||
);
|
||||
}
|
||||
}else{
|
||||
$this->error_message = t("Node @id does not exists", array('@id'=>$id));
|
||||
}
|
||||
}
|
||||
|
||||
private function checkChutier(){
|
||||
$default_chutier_id = $this->userdata->get('edlp_studio', $this->user->id(), 'default_chutier');
|
||||
// dpm($this->default_chutier_id);
|
||||
$this->chutier = entity_load('chutier', $default_chutier_id);
|
||||
// if default chutier does not exists, create, save and record it
|
||||
if(!$this->chutier){
|
||||
$this->createDefaultChutier();
|
||||
}
|
||||
}
|
||||
|
||||
private function createDefaultChutier(){
|
||||
// dpm('createDefaultChutier');
|
||||
$this->createChutier();
|
||||
$this->userdata->set('edlp_studio', $this->user->id(), 'default_chutier', $this->chutier->id());
|
||||
}
|
||||
|
||||
public function createChutier(){
|
||||
$chutier = array(
|
||||
'id' => NULL,
|
||||
'uid' => $this->user->id(),
|
||||
'status' => TRUE,
|
||||
'name' => t('Default'),
|
||||
);
|
||||
$this->chutier = entity_create('chutier', $chutier);
|
||||
$this->chutier->save();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\User\UserDataInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
use Drupal\edlp_studio\Entity\Compositon;
|
||||
|
||||
/**
|
||||
* Class CompositionController.
|
||||
*/
|
||||
class CompositionController extends ControllerBase {
|
||||
|
||||
protected $user;
|
||||
protected $userdata;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct(AccountInterface $account, UserDataInterface $userdata) {
|
||||
$this->user = $account;
|
||||
$this->userdata = $userdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
// Instantiates this form class.
|
||||
return new static(
|
||||
// Load the service required to construct this class.
|
||||
$container->get('current_user'),
|
||||
$container->get('user.data')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* AdddContent.
|
||||
*
|
||||
* @return json
|
||||
* Return status.
|
||||
*/
|
||||
public function CompositionActionJson($action, $cid, Request $request) {
|
||||
$this->error_message = null;
|
||||
$status = 'ok';
|
||||
$message = 'Hello';
|
||||
|
||||
$response = new JsonResponse();
|
||||
|
||||
switch($action){
|
||||
case 'create':
|
||||
$name = $request->query->get('new_name');
|
||||
if($name){
|
||||
$this->createComposition($name);
|
||||
}else{
|
||||
$this->error_message = t("Composition creation needs a name as query paramater!");
|
||||
}
|
||||
break;
|
||||
case 'open':
|
||||
if($cid){
|
||||
$this->openComposition($cid);
|
||||
}else{
|
||||
$this->error_message = t("Composition opening needs a cid as url paramater!");
|
||||
}
|
||||
break;
|
||||
case 'save':
|
||||
if($cid){
|
||||
$name = $request->query->get('new_name');
|
||||
$documents = $request->query->get('documents');
|
||||
$this->saveComposition($cid, $name, $documents);
|
||||
}else{
|
||||
$this->error_message = t("Composition saving needs a cid as query paramater!");
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
if($cid){
|
||||
$this->deleteComposition($cid);
|
||||
}else{
|
||||
$this->error_message = t("Composition deletion needs a cid as url paramater!");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if($this->error_message){
|
||||
$status = 'error';
|
||||
$message = $this->error_message;
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'action' => $action,
|
||||
'status' => $status,
|
||||
'message' => $this->error_message
|
||||
);
|
||||
if($status == 'ok'){
|
||||
switch ($action) {
|
||||
case 'create':
|
||||
$url = Url::fromRoute('entity.composition.canonical', ['composition' => $this->compo->id()], ['absolute' => TRUE]);
|
||||
$title = $this->compo->getName();
|
||||
$new_link_build = array(
|
||||
'#title' => $title,
|
||||
'#type' => 'link',
|
||||
'#url' => $url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $url->getInternalPath(),
|
||||
'cid' => $this->compo->id(),
|
||||
'class' => ['composition-link'],
|
||||
'title'=>$title,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$delete_url = Url::fromRoute('edlp_studio.composition_controller_action_ajax', ['action' => 'delete', 'cid' => $this->compo->id()], ['absolute' => TRUE]);
|
||||
|
||||
$deletelink_build = array(
|
||||
'#title' => t('Delete'),
|
||||
'#type' => 'link',
|
||||
'#url' => $delete_url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $delete_url->getInternalPath(),
|
||||
'cid' => $this->compo->id(),
|
||||
'class' => ['delete-composition-link'],
|
||||
'title'=>t('Delete @title', array('@title'=>$title)),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$data += array(
|
||||
'new_name' => $title,
|
||||
'new_link' => render($new_link_build),
|
||||
'delete_link' => render($deletelink_build),
|
||||
);
|
||||
break;
|
||||
case 'open':
|
||||
$this->getRendredComposition();
|
||||
$data += array(
|
||||
'compo' => $this->rendered_compo,
|
||||
);
|
||||
break;
|
||||
case 'save':
|
||||
$data += array(
|
||||
'name'=>$name,
|
||||
'documents'=>$documents
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$response->setData($data);
|
||||
return $response;
|
||||
|
||||
// // classic html
|
||||
// return array(
|
||||
// '#markup'=>'Status : ' . $status . ' | Message : ' . $message,
|
||||
// );
|
||||
}
|
||||
|
||||
private function createComposition($name){
|
||||
$compo = array(
|
||||
'id' => NULL,
|
||||
'uid' => $this->user->id(),
|
||||
'status' => TRUE,
|
||||
'name' => $name,
|
||||
);
|
||||
$this->compo = entity_create('composition', $compo);
|
||||
$this->compo->save();
|
||||
}
|
||||
|
||||
private function getRendredComposition(){
|
||||
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('composition');
|
||||
$compobuild = $view_builder->view($this->compo, 'studio_ui');
|
||||
$this->rendered_compo = render($compobuild);
|
||||
}
|
||||
|
||||
private function openComposition($cid){
|
||||
$this->compo = entity_load('composition', $cid);
|
||||
}
|
||||
|
||||
private function saveComposition($cid, $name = "", $new_documents = array()){
|
||||
$this->compo = entity_load('composition', $cid);
|
||||
if($name != ""){
|
||||
$this->compo->setName($name);
|
||||
}
|
||||
$documents = array();
|
||||
if(count($new_documents)){
|
||||
foreach ($new_documents as $nid) {
|
||||
$documents[] = ['target_id'=>$nid];
|
||||
}
|
||||
}
|
||||
$this->compo->set('documents', $documents);
|
||||
$this->compo->save();
|
||||
}
|
||||
|
||||
|
||||
private function deleteComposition($cid){
|
||||
$this->compo = entity_load('composition', $cid);
|
||||
$this->compo->delete();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\User\UserDataInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
// use Drupal\Core\Cache\CacheableJsonResponse;
|
||||
// use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\core\render\RenderContext;
|
||||
|
||||
use Drupal\edlp_studio\Entity\Chutier;
|
||||
|
||||
|
||||
/**
|
||||
* Class StudioUIController.
|
||||
*/
|
||||
class StudioUIController extends ControllerBase {
|
||||
|
||||
protected $user;
|
||||
protected $userdata;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*/
|
||||
public function __construct(AccountInterface $account, UserDataInterface $userdata) {
|
||||
$this->user = $account;
|
||||
$this->userdata = $userdata;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
// Instantiates this form class.
|
||||
return new static(
|
||||
// Load the service required to construct this class.
|
||||
$container->get('current_user'),
|
||||
$container->get('user.data')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Studio-ui.
|
||||
*
|
||||
* @return array
|
||||
* Return renderable array.
|
||||
*/
|
||||
public function StudioUI() {
|
||||
return $this->buildStudioUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Studio-ui.
|
||||
*
|
||||
* @return array
|
||||
* Return renderable array.
|
||||
*/
|
||||
public function StudioUIJson() {
|
||||
$renderable = $this->buildStudioUI();
|
||||
$rendered = render($renderable);
|
||||
|
||||
$data = ['rendered'=>$rendered];
|
||||
|
||||
// translations links
|
||||
// use Drupal\Core\Url;
|
||||
// use Drupal\Core\Language\LanguageInterface;
|
||||
$route_name = 'edlp_studio.studio_ui';
|
||||
$links = \Drupal::languageManager()->getLanguageSwitchLinks(LanguageInterface::TYPE_URL, Url::fromRoute($route_name));
|
||||
if (isset($links->links)) {
|
||||
$translations_build = [
|
||||
'#theme' => 'links__language_block',
|
||||
'#links' => $links->links,
|
||||
'#attributes' => ['class' => ["language-switcher-{$links->method_id}",],],
|
||||
'#set_active_class' => TRUE,
|
||||
];
|
||||
$translations_rendered = \Drupal::service('renderer')->executeInRenderContext(new RenderContext(), function () use ($translations_build) {return render($translations_build);});
|
||||
|
||||
$data['translations_links'] = $translations_rendered;
|
||||
}
|
||||
|
||||
// JSON
|
||||
$response = new JsonResponse();
|
||||
$response->setData($data);
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
public function StudioChutierUIJson(){
|
||||
$renderable = $this->buildChutierUI();
|
||||
$rendered = render($renderable);
|
||||
// TODO: make response cachable
|
||||
// JSON
|
||||
$response = new JsonResponse();
|
||||
$response->setData([
|
||||
'rendered'=> $rendered,
|
||||
]);
|
||||
return $response;
|
||||
}
|
||||
|
||||
private function buildStudioUI(){
|
||||
return [
|
||||
'#theme' => 'edlp_studio_ui',
|
||||
'#chutier_ui' => $this->buildChutierUI(),
|
||||
'#composition_ui' => $this->buildCompostionUI(),
|
||||
];
|
||||
}
|
||||
|
||||
private function buildChutierUI(){
|
||||
// get his docs in chutier
|
||||
$documents_nids = Chutier::getUserChutiersContents($this->user->id());
|
||||
// dpm($documents_nids);
|
||||
|
||||
$documents = entity_load_multiple('node', $documents_nids);
|
||||
|
||||
// build content renderable array
|
||||
$chutier_ui = array(
|
||||
"#theme"=>'edlp_chutier_ui',
|
||||
'#title' => t('Favorites'),
|
||||
"#document_nodes" => $documents,
|
||||
'#uid' => $this->user->id(),
|
||||
);
|
||||
|
||||
return $chutier_ui;
|
||||
}
|
||||
|
||||
private function buildCompostionUI(){
|
||||
|
||||
// build content renderable array
|
||||
$composition_ui = array(
|
||||
"#theme"=>'edlp_composition_ui',
|
||||
"#title" => t('Composition'),
|
||||
"#compositions" => $this->buildCompostionsList(),
|
||||
"#composer_header" => t("Create a new playlist, then drag and drop your bookmarked sounds on the timeline below"),
|
||||
"#lastcomposition" => $this->getLastCompo(),
|
||||
'#composer_actions' => array(
|
||||
'play_composition'=>array(
|
||||
"#type"=>'container',
|
||||
"#attributes"=>array(
|
||||
"class"=>array("compo-player-controls")
|
||||
)
|
||||
),// TODO: add social media links (what about composition visibility uotside studio_ui ?)
|
||||
),
|
||||
);
|
||||
|
||||
return $composition_ui;
|
||||
}
|
||||
|
||||
private function buildCompostionsList(){
|
||||
// get compositions
|
||||
$query = \Drupal::entityQuery('composition')
|
||||
->condition('user_id', $this->user->id());
|
||||
|
||||
$compos_ids = $query->execute();
|
||||
// dpm($compos_ids);
|
||||
|
||||
if(!count($compos_ids)){
|
||||
// create default compos
|
||||
$def_compos = \Drupal::entityManager()
|
||||
->getStorage('composition')
|
||||
->create(array(
|
||||
'name' => 'composition',
|
||||
'uid' => $this->user->id()
|
||||
)
|
||||
);
|
||||
$def_compos->save();
|
||||
$compos_ids = array($def_compos->id());
|
||||
}
|
||||
|
||||
$compos = entity_load_multiple('composition', $compos_ids);
|
||||
|
||||
$createurl = Url::fromRoute('edlp_studio.composition_controller_action_ajax', ['action' => 'create'], ['absolute' => TRUE]);
|
||||
|
||||
return array(
|
||||
'#theme' => 'edlp_compositions_list',
|
||||
'#composition_entities' => $compos,
|
||||
'#new_composition_url' => $createurl,
|
||||
);
|
||||
}
|
||||
|
||||
private function getLastCompo(){
|
||||
// just get the last compositions
|
||||
$query = \Drupal::entityQuery('composition')
|
||||
->condition('user_id', $this->user->id())
|
||||
->range(0,1)
|
||||
->sort('created');
|
||||
|
||||
$compos_id = $query->execute();
|
||||
if(count($compos_id)){
|
||||
$lastcompo = entity_load('composition', array_pop($compos_id));
|
||||
}else{
|
||||
$lastcompo = null;
|
||||
}
|
||||
|
||||
return $lastcompo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user