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', 'DESC'); $compos_id = $query->execute(); if(count($compos_id)){ $lastcompo = entity_load('composition', array_pop($compos_id)); }else{ $lastcompo = null; } return $lastcompo; } }