reinstaled drupal core using composer-drupal/drupal-project
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains chutier.page.inc.
|
||||
*
|
||||
* Page callback for Chutier entities.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
/**
|
||||
* Prepares variables for Chutier templates.
|
||||
*
|
||||
* Default template: chutier.html.twig.
|
||||
*
|
||||
* @param array $variables
|
||||
* An associative array containing:
|
||||
* - elements: An associative array containing the user information and any
|
||||
* - attributes: HTML attributes for the containing element.
|
||||
*/
|
||||
function template_preprocess_chutier(array &$variables) {
|
||||
// Fetch Chutier Entity Object.
|
||||
$chutier = $variables['elements']['#chutier'];
|
||||
|
||||
// Helpful $content variable for templates.
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
$variables['content'][$key] = $variables['elements'][$key];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains composition.page.inc.
|
||||
*
|
||||
* Page callback for Composition entities.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
/**
|
||||
* Prepares variables for Composition templates.
|
||||
*
|
||||
* Default template: composition.html.twig.
|
||||
*
|
||||
* @param array $variables
|
||||
* An associative array containing:
|
||||
* - elements: An associative array containing the user information and any
|
||||
* - attributes: HTML attributes for the containing element.
|
||||
*/
|
||||
function template_preprocess_composition(array &$variables) {
|
||||
// dpm($variables);
|
||||
// Fetch Composition Entity Object.
|
||||
$composition = $variables['elements']['#composition'];
|
||||
|
||||
// Helpful $content variable for templates.
|
||||
foreach (Element::children($variables['elements']) as $key) {
|
||||
$variables['content'][$key] = $variables['elements'][$key];
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
|
||||
(function($,Drupal,drupalSettings){var _settings=drupalSettings.edlp_studio;var $composer;function init(){initEvents();initStudio();};function initEvents(){$('body').on('new-audio-cartel-loaded',initAjaxChutierLinks).on('new-content-ajax-loaded',initStudio).on('all-modal-closed',initStudio);};function initStudio(){if($('#studio-ui').length){$composer=$('.composition_ui .composer','#studio-ui');initAjaxChutierLinks();initAjaxCompoLinks();initDragAndDropUI();$('body').trigger({'type':'studio-initialized'});}else{$('body').trigger({'type':'studio-not-active'});}}
|
||||
function initAjaxChutierLinks(){$('.chutier-ajax-link:not(.ajax-enabled)').addClass('ajax-enabled').on('click',onClickChutierAjaxLink);};function onClickChutierAjaxLink(e){e.preventDefault();addRemoveToChutier($(this));return false;};function addRemoveToChutier($link){var ajax_path=$link.attr('data-drupal-link-system-path');var path=window.location.origin+drupalSettings.path.baseUrl+ajax_path;$link.addClass('ajax-loading');$.getJSON(path,{}).done(function(data){onActionToChutierDone($link,data);}).fail(function(jqxhr,textStatus,error){onErrorActionToChutier(jqxhr,textStatus,error,$link);});};function onActionToChutierDone($link,data){$('body').trigger({'type':'chutier-action-done','action_done':data.action_done,'new_action':data.action_done=='add'?'remove':'add','target_id':$link.attr('target_id'),});$link.replaceWith(data.new_link);initAjaxChutierLinks();updateStudioChutier();};function onErrorActionToChutier(jqxhr,textStatus,error,$link){void 0;};function initAjaxCompoLinks(){$('.new-composition-link:not(.ajax-enabled)').on('click',onClickNewCompoLink).addClass('ajax-enabled');$('.composition-link:not(.ajax-enabled)').on('click',onClickCompoLink).addClass('ajax-enabled');$('.delete-composition-link:not(.ajax-enabled)').on('click',onClickDeleteCompoLink).addClass('ajax-enabled');};function onClickCompoLink(e){e.preventDefault();openCompo($(this));return false;};function openCompo($link){var cid=$link.attr('cid');var ajax_path=_settings.open_compo_ajax_url+'/'+cid;var path=window.location.origin+Drupal.url(ajax_path);$link.addClass('ajax-loading');$composer.addClass('ajax-loading');$.getJSON(path,{}).done(function(data){onOpenCompoDone(data,$link);}).fail(function(jqxhr,textStatus,error){onErrorOpenCompo(jqxhr,textStatus,error,$link);});};function onOpenCompoDone(data,$link){$('.composition-link').removeClass('is-active');$link.removeClass('ajax-loading').addClass('is-active');if($('.composition',$composer).length){$('.composition',$composer).replaceWith(data.compo);}else{$('header',$composer).after(data.compo);}
|
||||
$composer.removeClass('ajax-loading');initDragAndDropUI();$('body').trigger({'type':'on-studio-compo-opened'});};function onErrorOpenCompo(jqxhr,textStatus,error,$link){$link.removeClass('ajax-loading');void 0;};function onClickNewCompoLink(e){e.preventDefault();setInputForNewCompoName($(this));return false;};function setInputForNewCompoName($link){var $form=$('<form>').addClass('new-compo-form').append($('<input>').attr('type','text').attr('placeholder','new name')).append($('<button>').attr('type','submit').html('+')).submit(function(e){onNewCompoFormSubmit(e,$link,$(this));});$link.after($form).addClass('folded');$form.children('input[type="text"]').focus();};function onNewCompoFormSubmit(e,$link,$form){var name=$('input[type="text"]',$form).val();if(name!=''){$form.addClass('ajax-loading').children('*').attr('disabled','disabled');createNewCompo(name,$link,$form);}
|
||||
e.preventDefault();};function createNewCompo(name,$link,$form){var ajax_path=$link.attr('data-drupal-link-system-path');var path=window.location.origin+drupalSettings.path.baseUrl+ajax_path;$.getJSON(path,{'new_name':name}).done(function(data){onCreateCompoDone(data,$link,$form);}).fail(function(jqxhr,textStatus,error){onErrorCreateCompo(jqxhr,textStatus,error,$link);});};function onCreateCompoDone(data,$link,$form){var $new_link=$(data.new_link);var $delete_link=$(data.delete_link);$link.removeClass('folded').parents('li').before($('<li>').append($new_link).append($delete_link));$form.remove();initAjaxCompoLinks();openCompo($new_link);};function onErrorCreateCompo(jqxhr,textStatus,error,$link){void 0;};function onClickDeleteCompoLink(e){e.preventDefault();deleteCompo($(this));return false;};function deleteCompo($link){var ajax_path=$link.attr('data-drupal-link-system-path');var path=window.location.origin+Drupal.url(ajax_path);$link.parents('li').addClass('ajax-loading');$.getJSON(path,{}).done(function(data){onDeleteCompoDone(data,$link);}).fail(function(jqxhr,textStatus,error){onErrorDeleteCompo(jqxhr,textStatus,error,$link);});};function onDeleteCompoDone(data,$link,$form){if(data.status=="ok"){$link.parents('li').remove();if($('.composition-link').length){openCompo($('.composition-link').eq(0));}else{$('.composition',$composer).html();}}else{void 0;}};function onErrorDeleteCompo(jqxhr,textStatus,error,$link){$link.parents('li').removeClass('ajax-loading');void 0;};function updateStudioChutier(){$studioChutier=$('#studio-ui .chutier_ui');if($studioChutier.length){var ajax_path=_settings.chutier_ui_ajax;var path=window.location.origin+drupalSettings.path.baseUrl+ajax_path;$studioChutier.addClass('loading');$.getJSON(path,{}).done(function(data){onLoadedChutier($studioChutier,data);}).fail(function(jqxhr,textStatus,error){onLoadChutierError(jqxhr,textStatus,error,$studioChutier);});}};function onLoadedChutier($studioChutier,data){$studioChutier.replaceWith(data.rendered);initAjaxChutierLinks();setChutierDraggable();$('body').trigger({'type':'on-studio-chutier-updated'});}
|
||||
function onLoadChutierError(jqxhr,textStatus,error,$studioChutier){void 0;$studioChutier.removeClass('loading');}
|
||||
function initDragAndDropUI(){if(!$('.composition_ui .composer .composition .field--name-documents').length){$field_documents=$('<div>').addClass('field').addClass('field--name-documents').appendTo('.composition_ui .composer .composition');}else{$field_documents=$('.composition_ui .composer .composition .field--name-documents');$('.field__item',$field_documents).each(function(i){$(this).prepend($('<span>').addClass('handler'));});}
|
||||
var $remove_zone=$('<div>').addClass('remove-drop-zone').appendTo('.composition_ui .composer .composition').droppable({tolerance:'pointer',over:function(e,ui){ui.draggable.addClass('ready-to-remove');},out:function(e,ui){ui.draggable.removeClass('ready-to-remove');},drop:function(e,ui){ui.draggable.remove();}});$field_documents.sortable({revert:false,handle:".handler",receive:function(e,ui){$('.field__item',this).attr('style','');},update:function(e,ui){onOrderChanged(e,ui);},connectWith:$remove_zone,});setChutierDraggable();};function setChutierDraggable(){$('.chutier_ui .item-list li>div').draggable({containment:$('#studio-ui'),scroll:false,helper:function(e){return $('<div>').addClass('field__item').append($('<article>').addClass('node').append($('<h2>').addClass('node-title').append($('.audio-link',this).clone().removeClass('ajax-enable')))).prepend($('<span>').addClass('handler'));},cursorAt:{bottom:10,left:10},zIndex:999,revert:true,revertDuration:0,connectToSortable:$('.composition_ui .composer .composition .field--name-documents'),});}
|
||||
function onOrderChanged(e,ui){var cid=$(e.target).parents('.composition').attr('cid');var documents={};$('a',e.target).each(function(i){documents[i]=$(this).attr('nid');});recordCompoList(cid,documents);};function recordCompoList(cid,docs){var ajax_path=_settings.save_compo_ajax_url+'/'+cid;var path=window.location.origin+Drupal.url(ajax_path);$.getJSON(path,{documents:docs}).done(function(data){onRecordCompoDone(data);}).fail(function(jqxhr,textStatus,error){onErrorRecordCompo(jqxhr,textStatus,error);});$('body').trigger({'type':'on-studio-compo-updated'});}
|
||||
function onRecordCompoDone(data){if(data.status=="ok"){}else{void 0;}};function onErrorRecordCompo(jqxhr,textStatus,error){void 0;};init();})(jQuery,Drupal,drupalSettings);
|
||||
@@ -0,0 +1,408 @@
|
||||
(function ($, Drupal, drupalSettings) {
|
||||
|
||||
var _settings = drupalSettings.edlp_studio;
|
||||
var $composer;
|
||||
|
||||
// audio play is handled by edlp_theme
|
||||
|
||||
function init(){
|
||||
// console.log('Studio Init');
|
||||
initEvents();
|
||||
initStudio();
|
||||
};
|
||||
|
||||
function initEvents(){
|
||||
$('body')
|
||||
.on('new-audio-cartel-loaded', initAjaxChutierLinks)
|
||||
.on('new-content-ajax-loaded', initStudio)
|
||||
.on('all-modal-closed', initStudio);
|
||||
};
|
||||
|
||||
function initStudio(){
|
||||
if($('#studio-ui').length){
|
||||
$composer = $('.composition_ui .composer', '#studio-ui');
|
||||
initAjaxChutierLinks();
|
||||
initAjaxCompoLinks();
|
||||
initDragAndDropUI();
|
||||
$('body').trigger({'type':'studio-initialized'});
|
||||
}else{
|
||||
$('body').trigger({'type':'studio-not-active'});
|
||||
}
|
||||
}
|
||||
|
||||
// ___ _ _ _ _ _ _ _ _ _
|
||||
// / __| |_ _ _| |_(_)___ _ _ | \| |___ __| |___ | | (_)_ _ | |__ ___
|
||||
// | (__| ' \ || | _| / -_) '_| | .` / _ \/ _` / -_) | |__| | ' \| / /(_-<
|
||||
// \___|_||_\_,_|\__|_\___|_| |_|\_\___/\__,_\___| |____|_|_||_|_\_\/__/
|
||||
function initAjaxChutierLinks(){
|
||||
//console.log('studio initAjaxChutierLinks');
|
||||
$('.chutier-ajax-link:not(.ajax-enabled)')
|
||||
.addClass('ajax-enabled')
|
||||
.on('click', onClickChutierAjaxLink);
|
||||
};
|
||||
function onClickChutierAjaxLink(e){
|
||||
//console.log('studio onClickAjaxLink chutier');
|
||||
e.preventDefault();
|
||||
addRemoveToChutier($(this));
|
||||
return false;
|
||||
};
|
||||
function addRemoveToChutier($link){
|
||||
// var ajax_path = 'edlp_studio/ajax/chutier/add/'+id; // + '/' +cid;
|
||||
var ajax_path = $link.attr('data-drupal-link-system-path');
|
||||
var path = window.location.origin + drupalSettings.path.baseUrl + ajax_path;
|
||||
$link.addClass('ajax-loading');
|
||||
$.getJSON(path, {})
|
||||
.done(function(data){
|
||||
onActionToChutierDone($link, data);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error){
|
||||
onErrorActionToChutier(jqxhr, textStatus, error, $link);
|
||||
});
|
||||
};
|
||||
function onActionToChutierDone($link, data){
|
||||
//console.log('onActionToChutierDone',data);
|
||||
$('body').trigger({
|
||||
'type':'chutier-action-done',
|
||||
'action_done':data.action_done,
|
||||
'new_action':data.action_done == 'add' ? 'remove' : 'add',
|
||||
'target_id':$link.attr('target_id'),
|
||||
});
|
||||
$link.replaceWith(data.new_link);
|
||||
initAjaxChutierLinks();
|
||||
// reload Studio chutier_ui's documents list
|
||||
updateStudioChutier();
|
||||
};
|
||||
function onErrorActionToChutier(jqxhr, textStatus, error, $link){
|
||||
console.warn('action to chuttier load failed : '+error, jqxhr.responseText);
|
||||
};
|
||||
|
||||
// ___ _ _ _
|
||||
// / __|___ _ __ _ __ ___ __(_) |_(_)___ _ _ ___
|
||||
// | (__/ _ \ ' \| '_ \/ _ (_-< | _| / _ \ ' \(_-<
|
||||
// \___\___/_|_|_| .__/\___/__/_|\__|_\___/_||_/__/
|
||||
// |_|
|
||||
function initAjaxCompoLinks(){
|
||||
//console.log('studio initAjaxCompoLinks');
|
||||
$('.new-composition-link:not(.ajax-enabled)')
|
||||
.on('click', onClickNewCompoLink)
|
||||
.addClass('ajax-enabled');
|
||||
$('.composition-link:not(.ajax-enabled)')
|
||||
.on('click', onClickCompoLink)
|
||||
.addClass('ajax-enabled');
|
||||
$('.delete-composition-link:not(.ajax-enabled)')
|
||||
.on('click', onClickDeleteCompoLink)
|
||||
.addClass('ajax-enabled');
|
||||
};
|
||||
|
||||
// ___ ___
|
||||
// / _ \ _ __ ___ _ _ / __|___ _ __ _ __ ___
|
||||
// | (_) | '_ \/ -_) ' \ | (__/ _ \ ' \| '_ \/ _ \
|
||||
// \___/| .__/\___|_||_| \___\___/_|_|_| .__/\___/
|
||||
// |_| |_|
|
||||
function onClickCompoLink(e){
|
||||
e.preventDefault();
|
||||
//console.log('onClickCompoLink');
|
||||
openCompo($(this));
|
||||
return false;
|
||||
};
|
||||
function openCompo($link){
|
||||
var cid = $link.attr('cid');
|
||||
var ajax_path = _settings.open_compo_ajax_url+'/'+cid;
|
||||
var path = window.location.origin + Drupal.url(ajax_path);
|
||||
$link.addClass('ajax-loading');
|
||||
$composer.addClass('ajax-loading');
|
||||
$.getJSON(path, {})
|
||||
.done(function(data){
|
||||
onOpenCompoDone(data, $link);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error){
|
||||
onErrorOpenCompo(jqxhr, textStatus, error, $link);
|
||||
});
|
||||
};
|
||||
function onOpenCompoDone(data, $link){
|
||||
//console.log('onActionToCompoDone',data);
|
||||
$('.composition-link').removeClass('is-active');
|
||||
$link.removeClass('ajax-loading').addClass('is-active');
|
||||
if($('.composition', $composer).length){
|
||||
$('.composition', $composer).replaceWith(data.compo);
|
||||
}else{
|
||||
$('header', $composer).after(data.compo);
|
||||
}
|
||||
$composer.removeClass('ajax-loading');
|
||||
initDragAndDropUI();
|
||||
$('body').trigger({
|
||||
'type':'on-studio-compo-opened'
|
||||
});
|
||||
};
|
||||
function onErrorOpenCompo(jqxhr, textStatus, error, $link){
|
||||
$link.removeClass('ajax-loading');
|
||||
console.warn('open compo load failed : '+error, jqxhr.responseText);
|
||||
};
|
||||
|
||||
// _ _ _____ __ __ __ ___ _ __ _ __ ___
|
||||
// | ' \/ -_) V V / / _/ _ \ ' \| '_ \/ _ \
|
||||
// |_||_\___|\_/\_/ \__\___/_|_|_| .__/\___/
|
||||
// |_|
|
||||
function onClickNewCompoLink(e){
|
||||
e.preventDefault();
|
||||
setInputForNewCompoName($(this));
|
||||
return false;
|
||||
};
|
||||
function setInputForNewCompoName($link){
|
||||
var $form = $('<form>').addClass('new-compo-form')
|
||||
.append($('<input>').attr('type', 'text').attr('placeholder', 'new name'))
|
||||
.append($('<button>').attr('type', 'submit').html('+'))
|
||||
.submit(function(e){
|
||||
onNewCompoFormSubmit(e, $link, $(this));
|
||||
});
|
||||
|
||||
$link
|
||||
.after($form)
|
||||
.addClass('folded');
|
||||
$form.children('input[type="text"]').focus();
|
||||
};
|
||||
function onNewCompoFormSubmit(e, $link, $form){
|
||||
var name = $('input[type="text"]',$form).val();
|
||||
//console.log('onNewCompoFormSubmit', name);
|
||||
if(name != ''){
|
||||
$form.addClass('ajax-loading').children('*').attr('disabled', 'disabled');
|
||||
createNewCompo(name, $link, $form);
|
||||
}
|
||||
e.preventDefault();
|
||||
};
|
||||
function createNewCompo(name,$link, $form){
|
||||
var ajax_path = $link.attr('data-drupal-link-system-path');
|
||||
var path = window.location.origin + drupalSettings.path.baseUrl + ajax_path;
|
||||
// $link.addClass('ajax-loading');
|
||||
$.getJSON(path, {
|
||||
'new_name':name
|
||||
})
|
||||
.done(function(data){
|
||||
onCreateCompoDone(data, $link, $form);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error){
|
||||
onErrorCreateCompo(jqxhr, textStatus, error, $link);
|
||||
});
|
||||
};
|
||||
function onCreateCompoDone(data, $link, $form){
|
||||
//console.log('onActionToCompoDone',data);
|
||||
var $new_link = $(data.new_link);
|
||||
var $delete_link = $(data.delete_link);
|
||||
$link
|
||||
.removeClass('folded')
|
||||
.parents('li')
|
||||
.before($('<li>').append($new_link).append($delete_link));
|
||||
$form.remove();
|
||||
// open new composition to composer
|
||||
initAjaxCompoLinks();
|
||||
openCompo($new_link);
|
||||
};
|
||||
function onErrorCreateCompo(jqxhr, textStatus, error, $link){
|
||||
console.warn('action to compo load failed : '+error, jqxhr.responseText);
|
||||
};
|
||||
|
||||
// ___ _ _
|
||||
// | \ ___| |___| |_ ___ __ ___ _ __ _ __ ___
|
||||
// | |) / -_) / -_) _/ -_) / _/ _ \ ' \| '_ \/ _ \
|
||||
// |___/\___|_\___|\__\___| \__\___/_|_|_| .__/\___/
|
||||
// |_|
|
||||
function onClickDeleteCompoLink(e){
|
||||
e.preventDefault();
|
||||
// TODO: confirm compo deletion
|
||||
deleteCompo($(this));
|
||||
return false;
|
||||
};
|
||||
function deleteCompo($link){
|
||||
var ajax_path = $link.attr('data-drupal-link-system-path');
|
||||
var path = window.location.origin + Drupal.url(ajax_path);
|
||||
$link.parents('li').addClass('ajax-loading');
|
||||
$.getJSON(path, {})
|
||||
.done(function(data){
|
||||
onDeleteCompoDone(data, $link);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error){
|
||||
onErrorDeleteCompo(jqxhr, textStatus, error, $link);
|
||||
});
|
||||
};
|
||||
function onDeleteCompoDone(data, $link, $form){
|
||||
//console.log('onDeleteCompoDone',data);
|
||||
if(data.status == "ok"){
|
||||
$link.parents('li').remove();
|
||||
//console.log("$('.composition-link').length", $('.composition-link').length);
|
||||
if($('.composition-link').length){
|
||||
openCompo($('.composition-link').eq(0));
|
||||
}else{
|
||||
$('.composition', $composer).html();
|
||||
}
|
||||
}else{
|
||||
console.warn(data.message);
|
||||
}
|
||||
};
|
||||
function onErrorDeleteCompo(jqxhr, textStatus, error, $link){
|
||||
$link.parents('li').removeClass('ajax-loading');
|
||||
console.warn('delete compo load failed : '+error, jqxhr.responseText);
|
||||
};
|
||||
|
||||
// ___ _ _ _ _
|
||||
// / __| |_ _ _ __| (_)___ ___ _ _(_)
|
||||
// \__ \ _| || / _` | / _ \___| || | |
|
||||
// |___/\__|\_,_\__,_|_\___/ \_,_|_|
|
||||
// this seems dirty
|
||||
function updateStudioChutier(){
|
||||
$studioChutier = $('#studio-ui .chutier_ui');
|
||||
if($studioChutier.length){
|
||||
var ajax_path = _settings.chutier_ui_ajax;
|
||||
var path = window.location.origin + drupalSettings.path.baseUrl + ajax_path;
|
||||
$studioChutier.addClass('loading');
|
||||
$.getJSON(path, {})
|
||||
.done(function(data){
|
||||
onLoadedChutier($studioChutier, data);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error){
|
||||
onLoadChutierError(jqxhr, textStatus, error, $studioChutier);
|
||||
});
|
||||
}
|
||||
};
|
||||
function onLoadedChutier($studioChutier, data){
|
||||
$studioChutier.replaceWith(data.rendered);
|
||||
initAjaxChutierLinks();
|
||||
// set chutier element draggable again
|
||||
setChutierDraggable();
|
||||
$('body').trigger({
|
||||
'type':'on-studio-chutier-updated'
|
||||
});
|
||||
}
|
||||
function onLoadChutierError(jqxhr, textStatus, error, $studioChutier){
|
||||
console.warn('Chutier load failed', jqxhr.responseText);
|
||||
$studioChutier.removeClass('loading');
|
||||
|
||||
}
|
||||
|
||||
// ___ __ ___ _ _ ___
|
||||
// | \ _ _ __ _ __ _ / _|___ | \ _ _ ___ _ __ | | | |_ _|
|
||||
// | |) | '_/ _` / _` | > _|_ _| | |) | '_/ _ \ '_ \ | |_| || |
|
||||
// |___/|_| \__,_\__, | \_____| |___/|_| \___/ .__/ \___/|___|
|
||||
// |___/ |_|
|
||||
function initDragAndDropUI(){
|
||||
// check if field--name-documents exists
|
||||
if (!$('.composition_ui .composer .composition .field--name-documents').length) {
|
||||
// if not create it
|
||||
$field_documents = $('<div>')
|
||||
.addClass('field').addClass('field--name-documents')
|
||||
.appendTo('.composition_ui .composer .composition');
|
||||
}else{
|
||||
// add real dom square element to handle sorting
|
||||
$field_documents = $('.composition_ui .composer .composition .field--name-documents'); $('.field__item', $field_documents).each(function(i){
|
||||
$(this).prepend($('<span>').addClass('handler'));
|
||||
});
|
||||
}
|
||||
|
||||
// create remove dropzone
|
||||
var $remove_zone = $('<div>').addClass('remove-drop-zone')
|
||||
.appendTo('.composition_ui .composer .composition')
|
||||
.droppable({
|
||||
tolerance:'pointer',
|
||||
// scope:'composition_ui',
|
||||
over:function(e,ui){
|
||||
// console.log('on over remove : ui', ui);
|
||||
ui.draggable.addClass('ready-to-remove');
|
||||
},
|
||||
out:function(e,ui){
|
||||
// console.log('on over remove : ui', ui);
|
||||
ui.draggable.removeClass('ready-to-remove');
|
||||
},
|
||||
drop:function(e,ui){
|
||||
// console.log('on drop remove : ui', ui);
|
||||
ui.draggable.remove();
|
||||
// onOrderChanged(ui);
|
||||
}
|
||||
});
|
||||
|
||||
// create sortable
|
||||
$field_documents.sortable({
|
||||
revert:false,
|
||||
handle: ".handler",
|
||||
receive:function(e, ui){
|
||||
$('.field__item', this).attr('style', '');
|
||||
// TODO: trigger event to enable new audiolink player
|
||||
},
|
||||
update:function(e, ui){
|
||||
onOrderChanged(e, ui);
|
||||
},
|
||||
connectWith : $remove_zone,
|
||||
});
|
||||
|
||||
// set chutier element draggable
|
||||
setChutierDraggable();
|
||||
|
||||
};
|
||||
function setChutierDraggable(){
|
||||
$('.chutier_ui .item-list li>div').draggable({
|
||||
containment:$('#studio-ui'),
|
||||
scroll:false,
|
||||
helper:function(e){
|
||||
// we reproduce here the irem structure of destination sortable elements
|
||||
// var $audio_link = $('.audio-link',this);
|
||||
return $('<div>').addClass('field__item')
|
||||
.append(
|
||||
$('<article>').addClass('node').append(
|
||||
$('<h2>').addClass('node-title').append(
|
||||
// $('<a>')
|
||||
// .attr('nid', $audio_link.attr('nid'))
|
||||
// .html($audio_link.html())
|
||||
$('.audio-link',this).clone().removeClass('ajax-enable')
|
||||
)
|
||||
)
|
||||
)
|
||||
.prepend($('<span>').addClass('handler'));
|
||||
},
|
||||
// cursor:'grab',
|
||||
cursorAt:{bottom:10,left:10},
|
||||
zIndex:999,
|
||||
revert:true,
|
||||
revertDuration:0,
|
||||
connectToSortable:$('.composition_ui .composer .composition .field--name-documents'),
|
||||
});
|
||||
}
|
||||
function onOrderChanged(e, ui){
|
||||
//console.log('onOrderChanged : e', e);
|
||||
var cid = $(e.target).parents('.composition').attr('cid');
|
||||
var documents = {};
|
||||
$('a', e.target).each(function(i) {
|
||||
// console.log(this);
|
||||
documents[i] = $(this).attr('nid');
|
||||
});
|
||||
// console.log(documents);
|
||||
recordCompoList(cid, documents);
|
||||
};
|
||||
function recordCompoList(cid, docs){
|
||||
//console.log('recordCompoList '+cid, docs);
|
||||
var ajax_path = _settings.save_compo_ajax_url+'/'+cid;
|
||||
var path = window.location.origin + Drupal.url(ajax_path);
|
||||
//console.log('path', path);
|
||||
$.getJSON(path, {
|
||||
documents:docs
|
||||
})
|
||||
.done(function(data){
|
||||
onRecordCompoDone(data);
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error){
|
||||
onErrorRecordCompo(jqxhr, textStatus, error);
|
||||
});
|
||||
$('body').trigger({
|
||||
'type':'on-studio-compo-updated'
|
||||
});
|
||||
}
|
||||
function onRecordCompoDone(data){
|
||||
//console.log('onDeleteCompoDone',data);
|
||||
if(data.status == "ok"){
|
||||
}else{
|
||||
console.warn(data.message);
|
||||
}
|
||||
};
|
||||
function onErrorRecordCompo(jqxhr, textStatus, error){
|
||||
console.warn('record compo failed : '+error, jqxhr.responseText);
|
||||
};
|
||||
|
||||
init();
|
||||
})(jQuery, Drupal, drupalSettings);
|
||||
@@ -0,0 +1,7 @@
|
||||
name: 'Edlp Studio'
|
||||
type: module
|
||||
description: 'Edlp module that handle chutier and Compositions entities'
|
||||
core: 8.x
|
||||
package: Edlp
|
||||
dependencies:
|
||||
- entity_reference
|
||||
@@ -0,0 +1,10 @@
|
||||
edlp_studio-library:
|
||||
js:
|
||||
assets/dist/scripts/edlp_studio.min.js: { scope: footer }
|
||||
dependencies:
|
||||
- core/drupalSettings
|
||||
- core/jquery
|
||||
- core/jquery.once
|
||||
- core/jquery.ui.draggable
|
||||
- core/jquery.ui.droppable
|
||||
- core/jquery.ui.sortable
|
||||
@@ -0,0 +1,10 @@
|
||||
entity.chutier.add_form:
|
||||
route_name: entity.chutier.add_form
|
||||
title: 'Add Chutier'
|
||||
appears_on:
|
||||
- entity.chutier.collection
|
||||
entity.composition.add_form:
|
||||
route_name: entity.composition.add_form
|
||||
title: 'Add Composition'
|
||||
appears_on:
|
||||
- entity.composition.collection
|
||||
@@ -0,0 +1,34 @@
|
||||
edlp_studio.studio:
|
||||
title: 'Studio'
|
||||
route_name: edlp_studio.studio
|
||||
description: 'Edlp Studio configurations'
|
||||
parent: system.admin_structure
|
||||
weight: 100
|
||||
|
||||
# Chutier menu items definition
|
||||
entity.chutier.collection:
|
||||
title: 'Chutier list'
|
||||
route_name: entity.chutier.collection
|
||||
description: 'List Chutier entities'
|
||||
parent: edlp_studio.studio
|
||||
weight: 100
|
||||
|
||||
chutier.admin.structure.settings:
|
||||
title: 'Chutier settings'
|
||||
description: 'Configure Chutier entities'
|
||||
route_name: chutier.settings
|
||||
parent: edlp_studio.studio
|
||||
|
||||
# Composition menu items definition
|
||||
entity.composition.collection:
|
||||
title: 'Composition list'
|
||||
route_name: entity.composition.collection
|
||||
description: 'List Composition entities'
|
||||
parent: edlp_studio.studio
|
||||
weight: 100
|
||||
|
||||
composition.admin.structure.settings:
|
||||
title: 'Composition settings'
|
||||
description: 'Configure Composition entities'
|
||||
route_name: composition.settings
|
||||
parent: edlp_studio.studio
|
||||
@@ -0,0 +1,43 @@
|
||||
# Chutier routing definition
|
||||
chutier.settings_tab:
|
||||
route_name: chutier.settings
|
||||
title: 'Settings'
|
||||
base_route: chutier.settings
|
||||
|
||||
entity.chutier.canonical:
|
||||
route_name: entity.chutier.canonical
|
||||
base_route: entity.chutier.canonical
|
||||
title: 'View'
|
||||
|
||||
entity.chutier.edit_form:
|
||||
route_name: entity.chutier.edit_form
|
||||
base_route: entity.chutier.canonical
|
||||
title: 'Edit'
|
||||
|
||||
entity.chutier.delete_form:
|
||||
route_name: entity.chutier.delete_form
|
||||
base_route: entity.chutier.canonical
|
||||
title: Delete
|
||||
weight: 10
|
||||
|
||||
# Composition routing definition
|
||||
composition.settings_tab:
|
||||
route_name: composition.settings
|
||||
title: 'Settings'
|
||||
base_route: composition.settings
|
||||
|
||||
entity.composition.canonical:
|
||||
route_name: entity.composition.canonical
|
||||
base_route: entity.composition.canonical
|
||||
title: 'View'
|
||||
|
||||
entity.composition.edit_form:
|
||||
route_name: entity.composition.edit_form
|
||||
base_route: entity.composition.canonical
|
||||
title: 'Edit'
|
||||
|
||||
entity.composition.delete_form:
|
||||
route_name: entity.composition.delete_form
|
||||
base_route: entity.composition.canonical
|
||||
title: Delete
|
||||
weight: 10
|
||||
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains edlp_studio.module.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\edlp_studio\Entity\Chutier;
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function edlp_studio_help($route_name, RouteMatchInterface $route_match) {
|
||||
switch ($route_name) {
|
||||
// Main module help for the edlp_studio module.
|
||||
case 'help.page.edlp_studio':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('Edlp module that handle chutier and compositions entities') . '</p>';
|
||||
return $output;
|
||||
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_page_attachments().
|
||||
* @param array $attachments
|
||||
*/
|
||||
function edlp_studio_page_attachments(array &$attachments) {
|
||||
$attachments['#attached']['library'][] = 'edlp_studio/edlp_studio-library';
|
||||
// chutier ui
|
||||
$url = Url::fromRoute('edlp_studio.studio_chutier_ui_ajax', [], ['absolute' => TRUE]);
|
||||
$attachments['#attached']['drupalSettings']['edlp_studio']['chutier_ui_ajax'] = $url->getInternalPath();
|
||||
// open compo
|
||||
$url = Url::fromRoute('edlp_studio.composition_controller_action_ajax', ['action'=>'open'], ['absolute' => TRUE]);
|
||||
$attachments['#attached']['drupalSettings']['edlp_studio']['open_compo_ajax_url'] = $url->getInternalPath();
|
||||
// save compo
|
||||
$url = Url::fromRoute('edlp_studio.composition_controller_action_ajax', ['action'=>'save'], ['absolute' => TRUE]);
|
||||
$attachments['#attached']['drupalSettings']['edlp_studio']['save_compo_ajax_url'] = $url->getInternalPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function edlp_studio_theme($existing, $type, $theme, $path) {
|
||||
// @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
|
||||
|
||||
return array(
|
||||
'composition' => array(
|
||||
'file' => 'includes/composition.inc',
|
||||
'render element'=>'elements',
|
||||
),
|
||||
'edlp_chutier_ui' => array(
|
||||
'file' => 'includes/edlp_chutier_ui.inc',
|
||||
'variables' => array(
|
||||
'title' => t('Chutier'),
|
||||
'document_nodes' => array(),
|
||||
'uid' => null,
|
||||
),
|
||||
),
|
||||
'edlp_composition_ui' => array(
|
||||
'file' => 'includes/edlp_composition_ui.inc',
|
||||
'variables' => array(
|
||||
'title' => t('Compositon'),
|
||||
'compositions' => null,
|
||||
'composer_header' => null,
|
||||
'lastcomposition' => null,
|
||||
'composer_actions' => null,
|
||||
),
|
||||
),
|
||||
'edlp_compositions_list' => array(
|
||||
'file' => 'includes/edlp_compositions_list.inc',
|
||||
'variables' => array(
|
||||
'composition_entities' => array(),
|
||||
'new_composition_url' => Null,
|
||||
),
|
||||
),
|
||||
'edlp_studio_ui' => array(
|
||||
'file' => 'includes/edlp_studio_ui.inc',
|
||||
'variables' => array(
|
||||
'chutier_ui' => null,
|
||||
'composition_ui' => null,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme_suggestions_HOOK().
|
||||
*/
|
||||
function edlp_studio_theme_suggestions_composition(array $vars) {
|
||||
// dpm($vars);
|
||||
$suggestions = [];
|
||||
|
||||
/** @var \Drupal\edlp_studio\CompositionInterface $compo */
|
||||
$compo = $vars['elements']['#composition'];
|
||||
//
|
||||
$suggestions[] = 'composition';
|
||||
$suggestions[] = 'composition__' . $compo->id();
|
||||
$suggestions[] = 'composition__' . $vars['elements']['#view_mode'];
|
||||
$suggestions[] = 'composition__' . $compo->id() . '__' . $vars['elements']['#view_mode'];
|
||||
// $suggestions[] = 'taxonomy_term__' . $term->id();
|
||||
|
||||
// dpm($suggestions);
|
||||
return $suggestions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* hook_entity_extra_field_info()
|
||||
*
|
||||
*/
|
||||
function edlp_studio_entity_extra_field_info(){
|
||||
$extra = [];
|
||||
// TODO: get node content type by settings @see readme
|
||||
$extra['node']['enregistrement']['display']['chutier_actions'] = [
|
||||
'label' => t('Chutier actions'),
|
||||
'description' => 'Display a link to add the content to chutier',
|
||||
'weight' => 99,
|
||||
'visible' => FALSE,
|
||||
];
|
||||
return $extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ENTITY_TYPE_view().
|
||||
* @see https://www.amazeelabs.com/en/render-menu-tree-custom-code-drupal-8
|
||||
*/
|
||||
function edlp_studio_node_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
|
||||
$display_settings = $display->getComponent('chutier_actions');
|
||||
if (!empty($display_settings)) {
|
||||
// dpm($entity);
|
||||
// dpm($entity->id());
|
||||
$user = \Drupal::currentUser();
|
||||
// dpm($user);
|
||||
// check if user loged in ? no -> popup message : yes -> links
|
||||
$register_url = Url::fromRoute('user.register');
|
||||
|
||||
if($user->id() == 0){
|
||||
$build['chutier_actions'] = array(
|
||||
'#type' => 'container',
|
||||
'#attributes' => array(
|
||||
'class' => array('chutier-icon', 'not-logedin')
|
||||
),
|
||||
"popup"=>array(
|
||||
'#type'=>'container',
|
||||
'#attributes' => array(
|
||||
'class' => array('popup')
|
||||
),
|
||||
"content"=>array(
|
||||
'#type'=>'container',
|
||||
'#attributes' => array(
|
||||
'class' => array('inner')
|
||||
),
|
||||
'description'=>array(
|
||||
'#prefix'=>'<p>',
|
||||
'#markup'=>t('To bookmark sounds and make your own playlists, you must log in. Click the studio icon on the low-right corner of the page.'),
|
||||
'#suffix'=>'</p>'
|
||||
),
|
||||
// TODO: ajouter le login form
|
||||
'register'=>array(
|
||||
'#prefix'=>'<p>',
|
||||
'register'=> array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('Create new account'),
|
||||
'#url' => $register_url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $register_url->getInternalPath()
|
||||
)
|
||||
)
|
||||
),
|
||||
'#suffix'=>'</p>'
|
||||
),
|
||||
// 'login'=>array(
|
||||
// '#prefix'=>'<p>',
|
||||
// '#markup'=>t("Ou connectez vous en survolant l'icone du studio en bas a droite de la page"),
|
||||
// '#suffix'=>'</p>'
|
||||
// ),
|
||||
)
|
||||
)
|
||||
);
|
||||
}else{
|
||||
// TODO: check if user has permission 'use chutier'
|
||||
$url = Chutier::getActionsUrl($entity->id(), $user->id());
|
||||
$build['chutier_actions'] = array(
|
||||
'#type' => 'link',
|
||||
'#title' => 'Chutier',
|
||||
'#url' => $url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $url->getInternalPath()
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
administer studio:
|
||||
title: 'Administer studio'
|
||||
|
||||
# Chutiers
|
||||
add chutier entities:
|
||||
title: 'Create new Chutier entities'
|
||||
|
||||
administer chutier entities:
|
||||
title: 'Administer Chutier entities'
|
||||
description: 'Allow to access the administration form to configure Chutier entities.'
|
||||
restrict access: true
|
||||
|
||||
delete any chutier entities:
|
||||
title: 'Delete any Chutier entities'
|
||||
|
||||
edit any chutier entities:
|
||||
title: 'Edit any Chutier entities'
|
||||
|
||||
delete own chutier entities:
|
||||
title: 'Delete own Chutier entities'
|
||||
|
||||
edit own chutier entities:
|
||||
title: 'Edit own Chutier entities'
|
||||
|
||||
view published chutier entities:
|
||||
title: 'View published Chutier entities'
|
||||
|
||||
view any unpublished chutier entities:
|
||||
title: 'View any unpublished Chutier entities'
|
||||
|
||||
view own unpublished chutier entities:
|
||||
title: 'View own unpublished Chutier entities'
|
||||
|
||||
use chutier:
|
||||
title: 'use chutier'
|
||||
|
||||
# Compositions
|
||||
add composition entities:
|
||||
title: 'Create new Composition entities'
|
||||
|
||||
administer composition entities:
|
||||
title: 'Administer Composition entities'
|
||||
description: 'Allow to access the administration form to configure Composition entities.'
|
||||
restrict access: true
|
||||
|
||||
delete any composition entities:
|
||||
title: 'Delete any Composition entities'
|
||||
|
||||
edit any composition entities:
|
||||
title: 'Edit any Composition entities'
|
||||
|
||||
delete own composition entities:
|
||||
title: 'Delete own Composition entities'
|
||||
|
||||
edit own composition entities:
|
||||
title: 'Edit own Composition entities'
|
||||
|
||||
view published composition entities:
|
||||
title: 'View published Composition entities'
|
||||
|
||||
view any unpublished composition entities:
|
||||
title: 'View any unpublished Composition entities'
|
||||
|
||||
view own unpublished composition entities:
|
||||
title: 'View own unpublished Composition entities'
|
||||
@@ -0,0 +1,49 @@
|
||||
edlp_studio.studio:
|
||||
path: '/admin/structure/studio'
|
||||
defaults:
|
||||
_controller: '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage'
|
||||
_title: 'Studio'
|
||||
requirements:
|
||||
_permission: 'administer studio'
|
||||
|
||||
edlp_studio.chutier_controller_ajax_add_content:
|
||||
path: '/edlp_studio/ajax/chutier/{action}/{id}/{cid}'
|
||||
defaults:
|
||||
_controller: '\Drupal\edlp_studio\Controller\ChutierController::AddRemoveContent'
|
||||
_title: 'Add/remove content to/from chutier'
|
||||
cid: null
|
||||
requirements:
|
||||
_permission: 'use chutier'
|
||||
|
||||
edlp_studio.composition_controller_action_ajax:
|
||||
path: '/edlp_studio/ajax/composition/{action}/{cid}'
|
||||
defaults:
|
||||
_controller: '\Drupal\edlp_studio\Controller\CompositionController::CompositionActionJson'
|
||||
_title: 'Create, Delete or Rename composition'
|
||||
cid: null
|
||||
requirements:
|
||||
_permission: 'use chutier'
|
||||
|
||||
edlp_studio.studio_ui:
|
||||
path: '/studio'
|
||||
defaults:
|
||||
_controller: '\Drupal\edlp_studio\Controller\StudioUIController::StudioUI'
|
||||
_title: 'Studio User Interface'
|
||||
requirements:
|
||||
_permission: 'use chutier'
|
||||
|
||||
edlp_studio.studio_ui_ajax:
|
||||
path: '/studio/ajax'
|
||||
defaults:
|
||||
_controller: '\Drupal\edlp_studio\Controller\StudioUIController::StudioUIJson'
|
||||
_title: 'Studio User Interface'
|
||||
requirements:
|
||||
_permission: 'use chutier'
|
||||
|
||||
edlp_studio.studio_chutier_ui_ajax:
|
||||
path: '/studio/chutier-ui/ajax'
|
||||
defaults:
|
||||
_controller: '\Drupal\edlp_studio\Controller\StudioUIController::StudioChutierUIJson'
|
||||
_title: 'Chutier of Studio User Interface'
|
||||
requirements:
|
||||
_permission: 'use chutier'
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Drupal\Core\Render\Element;
|
||||
|
||||
|
||||
/**
|
||||
* Prepares variables for Composition templates.
|
||||
*
|
||||
* Default template: composition.html.twig.
|
||||
*
|
||||
* @param array $variables
|
||||
* An associative array containing:
|
||||
* - elements: An associative array containing the user information and any
|
||||
* - attributes: HTML attributes for the containing element.
|
||||
*/
|
||||
function template_preprocess_composition(array &$vars) {
|
||||
// dpm($variables);
|
||||
// Fetch Composition Entity Object.
|
||||
/** @var \Drupal\edlp_studio\CompositionInterface $composition */
|
||||
$composition = $vars['elements']['#composition'];
|
||||
|
||||
$vars['view_mode'] = $vars['elements']['#view_mode'];
|
||||
|
||||
// $vars['name'] = $composition->getName();
|
||||
// unset($vars['elements']['name']);
|
||||
|
||||
// $variables['page'] = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term);
|
||||
|
||||
$vars['url'] = $composition->url();
|
||||
|
||||
$vars['attributes']['cid'] = $composition->id();
|
||||
$vars['attributes']['class'] = array('composition');
|
||||
|
||||
// Helpful $content variable for templates.
|
||||
foreach (Element::children($vars['elements']) as $key) {
|
||||
$vars['content'][$key] = $vars['elements'][$key];
|
||||
}
|
||||
|
||||
// dpm($vars);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
use \Drupal\Core\Url;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
|
||||
use Drupal\edlp_studio\Entity\Chutier;
|
||||
|
||||
function template_preprocess_edlp_chutier_ui(&$vars){
|
||||
// dpm($vars);
|
||||
// $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
|
||||
|
||||
$vars['documents'] = array (
|
||||
'#theme' => 'item_list',
|
||||
'#items' => [],
|
||||
);
|
||||
foreach($vars['document_nodes'] as $node){
|
||||
// get the url
|
||||
$url = Url::fromRoute('entity.node.canonical', ['node' => $node->id()], ['absolute' => TRUE]);
|
||||
// get the audio file url
|
||||
$field_son_values = $node->get('field_son')->getValue();
|
||||
$son_fid = count($field_son_values) ? $field_son_values[0]['target_id'] : "";
|
||||
$son_file = \Drupal\file\Entity\File::load($son_fid);
|
||||
$son_url = null;
|
||||
if($son_file){
|
||||
$son_uri = $son_file->getFileUri();
|
||||
$son_url = file_create_url($son_uri);
|
||||
}
|
||||
// get the title
|
||||
$title = $node->getTitle();
|
||||
if(!$title) continue;
|
||||
$trunc_title = Unicode::truncate($title, 25, true, true);
|
||||
// classes
|
||||
$classes = array('audio-link', 'ajax-link');
|
||||
// get the entries
|
||||
$entrees = '';
|
||||
foreach ($node->get('field_entrees')->getValue() as $key => $term) {
|
||||
$entrees .= '<span class="entree" tid="'.$term['target_id'].'"></span>';
|
||||
}
|
||||
//
|
||||
// get the remove url (obviously as we are in chutier all contents actions are remove ;)
|
||||
$remove_url = Chutier::getActionsUrl($node->id(), $vars['uid']);
|
||||
|
||||
// build the link
|
||||
$vars['documents']['#items'][] = array(
|
||||
'#type' => 'container',
|
||||
'entrees' => array(
|
||||
'#type' => 'container',
|
||||
'#attributes'=>['class'=>['entrees']],
|
||||
'#markup'=>$entrees,
|
||||
),
|
||||
'link'=>array(
|
||||
'#title' => $trunc_title,
|
||||
'#type' => 'link',
|
||||
'#url' => $url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $url->getInternalPath(),
|
||||
'audio_url' => $son_url,
|
||||
'nid' => $node->id(),
|
||||
// 'tid' => $entrees[mt_rand(0, count($entrees) - 1)],
|
||||
// 'entries_size' => count($entrees),
|
||||
'class' => $classes,
|
||||
'title'=>$title,
|
||||
),
|
||||
),
|
||||
),
|
||||
'remove_link' => array(
|
||||
'#title' => t("Chutier."),
|
||||
'#type' => 'link',
|
||||
'#url' => $remove_url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $remove_url->getInternalPath()
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
function template_preprocess_edlp_composition_ui(&$vars){
|
||||
// dpm($vars);
|
||||
|
||||
if($vars['lastcomposition']){
|
||||
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('composition');
|
||||
$vars['composition'] = $view_builder->view($vars['lastcomposition'], 'studio_ui');
|
||||
}else{
|
||||
$vars['composition'] = null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use \Drupal\Core\Url;
|
||||
use \Drupal\Component\Utility\Unicode;
|
||||
|
||||
function template_preprocess_edlp_compositions_list(&$vars){
|
||||
|
||||
$vars['compositions'] = array (
|
||||
'#theme' => 'item_list',
|
||||
'#items' => [],
|
||||
);
|
||||
$i = 0;
|
||||
foreach($vars['composition_entities'] as $entity){
|
||||
// get the url
|
||||
$url = Url::fromRoute('entity.composition.canonical',
|
||||
['composition' => $entity->id()], ['absolute' => TRUE]);
|
||||
// get the delete url
|
||||
$delete_url = Url::fromRoute('edlp_studio.composition_controller_action_ajax',
|
||||
['action' => 'delete', 'cid'=>$entity->id()], ['absolute' => TRUE]);
|
||||
|
||||
$title = $entity->getName();
|
||||
|
||||
$vars['compositions']['#items'][] = array(
|
||||
'compo_link' => array(
|
||||
'#title' => $title,
|
||||
'#type' => 'link',
|
||||
'#url' => $url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $url->getInternalPath(),
|
||||
'cid' => $entity->id(),
|
||||
'class' => ['composition-link', $i==0 ? 'is-active':''],
|
||||
'title'=>$title,
|
||||
),
|
||||
),
|
||||
),
|
||||
'delete_link' => array(
|
||||
'#title' => t("delete"),
|
||||
'#type' => 'link',
|
||||
'#url' => $delete_url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $delete_url->getInternalPath(),
|
||||
'cid' => $entity->id(),
|
||||
'class' => ['delete-composition-link'],
|
||||
'title'=> t('Delete @title', array('@title'=>$title)),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$i++;
|
||||
}
|
||||
|
||||
$vars['compositions']['#items'][] = array(
|
||||
'#title' => t('New composition'),
|
||||
'#type' => 'link',
|
||||
'#url' => $vars['new_composition_url'],
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $vars['new_composition_url']->getInternalPath(),
|
||||
'class' => ['new-composition-link']
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
function template_preprocess_edlp_studio_ui(&$vars){
|
||||
// dpm($vars);
|
||||
/*
|
||||
@see https://www.drupal8.ovh/index.php/en/tutoriels/339/render-a-node-or-an-entity
|
||||
*/
|
||||
// $view_builder = \Drupal::entityTypeManager()->getViewBuilder($vars['entity_type']);
|
||||
// $vars['content'] = $view_builder->view($vars['entity'], $vars['view_mode']);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
# Edlp Studio
|
||||
|
||||
## Chutier
|
||||
|
||||
TODO: get content types that could be added to chutier by settings ( maybe per each contenttypes settings )
|
||||
|
||||
|
||||
## Composition
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio;
|
||||
|
||||
use Drupal\Core\Entity\EntityAccessControlHandler;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
||||
/**
|
||||
* Access controller for the Chutier entity.
|
||||
*
|
||||
* @see \Drupal\edlp_studio\Entity\Chutier.
|
||||
*/
|
||||
class ChutierAccessControlHandler extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
/** @var \Drupal\edlp_studio\Entity\ChutierInterface $entity */
|
||||
switch ($operation) {
|
||||
case 'view':
|
||||
if (!$entity->isPublished()) {
|
||||
if($account->hasPermission('view own unpublished chutier entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
|
||||
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
|
||||
}else{
|
||||
return AccessResult::allowedIfHasPermission($account, 'view any unpublished chutier entities');
|
||||
}
|
||||
}
|
||||
return AccessResult::allowedIfHasPermission($account, 'view published chutier entities');
|
||||
|
||||
case 'update':
|
||||
if($account->hasPermission('edit own chutier entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
|
||||
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
|
||||
}else{
|
||||
return AccessResult::allowedIfHasPermission($account, 'edit any chutier entities');
|
||||
}
|
||||
|
||||
case 'delete':
|
||||
if($account->hasPermission('delete own chutier entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
|
||||
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
|
||||
}else{
|
||||
return AccessResult::allowedIfHasPermission($account, 'delete chutier entities');
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown operation, no opinion.
|
||||
return AccessResult::neutral();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'add chutier entities');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Provides routes for Chutier entities.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class ChutierHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||
$collection = parent::getRoutes($entity_type);
|
||||
|
||||
$entity_type_id = $entity_type->id();
|
||||
|
||||
if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
|
||||
$collection->add("$entity_type_id.settings", $settings_form_route);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the settings form route.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type.
|
||||
*
|
||||
* @return \Symfony\Component\Routing\Route|null
|
||||
* The generated route, if available.
|
||||
*/
|
||||
protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
|
||||
if (!$entity_type->getBundleEntityType()) {
|
||||
$route = new Route("/admin/structure/{$entity_type->id()}/settings");
|
||||
$route
|
||||
->setDefaults([
|
||||
'_form' => 'Drupal\edlp_studio\Form\ChutierSettingsForm',
|
||||
'_title' => "{$entity_type->getLabel()} settings",
|
||||
])
|
||||
->setRequirement('_permission', $entity_type->getAdminPermission())
|
||||
->setOption('_admin_route', TRUE);
|
||||
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityListBuilder;
|
||||
use Drupal\Core\Link;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of Chutier entities.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
class ChutierListBuilder extends EntityListBuilder {
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['id'] = $this->t('Chutier ID');
|
||||
$header['name'] = $this->t('Name');
|
||||
$header['user'] = $this->t('User');
|
||||
// $header['default'] = $this->t('User id');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
/* @var $entity \Drupal\edlp_studio\Entity\Chutier */
|
||||
$row['id'] = $entity->id();
|
||||
$row['name'] = Link::createFromRoute(
|
||||
$entity->label(),
|
||||
'entity.chutier.edit_form',
|
||||
['chutier' => $entity->id()]
|
||||
);
|
||||
$row['user'] = Link::createFromRoute(
|
||||
$entity->getOwner()->getUserName(),
|
||||
'entity.user.canonical',
|
||||
['user' => $entity->getOwnerId()]
|
||||
);
|
||||
|
||||
// $row['uid'] = $entity->getOwnerId();
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio;
|
||||
|
||||
use Drupal\Core\Entity\EntityAccessControlHandler;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
|
||||
/**
|
||||
* Access controller for the Composition entity.
|
||||
*
|
||||
* @see \Drupal\edlp_studio\Entity\Composition.
|
||||
*/
|
||||
class CompositionAccessControlHandler extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
/** @var \Drupal\edlp_studio\Entity\CompositionInterface $entity */
|
||||
switch ($operation) {
|
||||
case 'view':
|
||||
if (!$entity->isPublished()) {
|
||||
if($account->hasPermission('view own unpublished composition entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
|
||||
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
|
||||
}else{
|
||||
return AccessResult::allowedIfHasPermission($account, 'view any unpublished composition entities');
|
||||
}
|
||||
}
|
||||
return AccessResult::allowedIfHasPermission($account, 'view published composition entities');
|
||||
|
||||
case 'update':
|
||||
if($account->hasPermission('edit own composition entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
|
||||
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
|
||||
}else{
|
||||
return AccessResult::allowedIfHasPermission($account, 'edit any composition entities');
|
||||
}
|
||||
|
||||
case 'delete':
|
||||
if($account->hasPermission('delete own composition entities') && $account->isAuthenticated() && $account->id() == $entity->getOwnerId() ){
|
||||
return AccessResult::allowed()->cachePerPermissions()->cachePerUser()->addCacheableDependency($entity);
|
||||
}else{
|
||||
return AccessResult::allowedIfHasPermission($account, 'delete composition entities');
|
||||
}
|
||||
}
|
||||
|
||||
// Unknown operation, no opinion.
|
||||
return AccessResult::neutral();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'add composition entities');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
/**
|
||||
* Provides routes for Composition entities.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
|
||||
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
|
||||
*/
|
||||
class CompositionHtmlRouteProvider extends AdminHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||
$collection = parent::getRoutes($entity_type);
|
||||
|
||||
$entity_type_id = $entity_type->id();
|
||||
|
||||
if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
|
||||
$collection->add("$entity_type_id.settings", $settings_form_route);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the settings form route.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type.
|
||||
*
|
||||
* @return \Symfony\Component\Routing\Route|null
|
||||
* The generated route, if available.
|
||||
*/
|
||||
protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
|
||||
if (!$entity_type->getBundleEntityType()) {
|
||||
$route = new Route("/admin/structure/studio/{$entity_type->id()}/settings");
|
||||
$route
|
||||
->setDefaults([
|
||||
'_form' => 'Drupal\edlp_studio\Form\CompositionSettingsForm',
|
||||
'_title' => "{$entity_type->getLabel()} settings",
|
||||
])
|
||||
->setRequirement('_permission', $entity_type->getAdminPermission())
|
||||
->setOption('_admin_route', TRUE);
|
||||
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio;
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\EntityListBuilder;
|
||||
use Drupal\Core\Link;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of Composition entities.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
class CompositionListBuilder extends EntityListBuilder {
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['id'] = $this->t('Composition ID');
|
||||
$header['name'] = $this->t('Name');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
/* @var $entity \Drupal\edlp_studio\Entity\Composition */
|
||||
$row['id'] = $entity->id();
|
||||
$row['name'] = Link::createFromRoute(
|
||||
$entity->label(),
|
||||
'entity.composition.edit_form',
|
||||
['composition' => $entity->id()]
|
||||
);
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityChangedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Defines the Chutier entity.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "chutier",
|
||||
* label = @Translation("Chutier"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\edlp_studio\ChutierListBuilder",
|
||||
* "views_data" = "Drupal\edlp_studio\Entity\ChutierViewsData",
|
||||
*
|
||||
* "form" = {
|
||||
* "default" = "Drupal\edlp_studio\Form\ChutierForm",
|
||||
* "add" = "Drupal\edlp_studio\Form\ChutierForm",
|
||||
* "edit" = "Drupal\edlp_studio\Form\ChutierForm",
|
||||
* "delete" = "Drupal\edlp_studio\Form\ChutierDeleteForm",
|
||||
* },
|
||||
* "access" = "Drupal\edlp_studio\ChutierAccessControlHandler",
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\edlp_studio\ChutierHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* base_table = "chutier",
|
||||
* admin_permission = "administer chutier entities",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "name",
|
||||
* "uuid" = "uuid",
|
||||
* "uid" = "user_id",
|
||||
* "langcode" = "langcode",
|
||||
* "status" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/admin/structure/studio/chutier/{chutier}",
|
||||
* "add-form" = "/admin/structure/studio/chutier/add",
|
||||
* "edit-form" = "/admin/structure/studio/chutier/{chutier}/edit",
|
||||
* "delete-form" = "/admin/structure/studio/chutier/{chutier}/delete",
|
||||
* "collection" = "/admin/structure/studio/chutier",
|
||||
* },
|
||||
* field_ui_base_route = "chutier.settings"
|
||||
* )
|
||||
*/
|
||||
class Chutier extends ContentEntityBase implements ChutierInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
|
||||
parent::preCreate($storage_controller, $values);
|
||||
$values += [
|
||||
'user_id' => \Drupal::currentUser()->id(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->get('name')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setName($name) {
|
||||
$this->set('name', $name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCreatedTime() {
|
||||
return $this->get('created')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setCreatedTime($timestamp) {
|
||||
$this->set('created', $timestamp);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOwner() {
|
||||
return $this->get('user_id')->entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOwnerId() {
|
||||
return $this->get('user_id')->target_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOwnerId($uid) {
|
||||
$this->set('user_id', $uid);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOwner(UserInterface $account) {
|
||||
$this->set('user_id', $account->id());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isPublished() {
|
||||
return (bool) $this->getEntityKey('status');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPublished($published) {
|
||||
$this->set('status', $published ? TRUE : FALSE);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Authored by'))
|
||||
->setDescription(t('The user ID of author of the Chutier entity.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setSetting('target_type', 'user')
|
||||
->setSetting('handler', 'default')
|
||||
->setTranslatable(TRUE)
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'author',
|
||||
'weight' => 0,
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
'weight' => 5,
|
||||
'settings' => [
|
||||
'match_operator' => 'CONTAINS',
|
||||
'size' => '60',
|
||||
'autocomplete_type' => 'tags',
|
||||
'placeholder' => '',
|
||||
],
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setDisplayConfigurable('view', TRUE);
|
||||
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Name'))
|
||||
->setDescription(t('The name of the Chutier entity.'))
|
||||
->setSettings([
|
||||
'max_length' => 50,
|
||||
'text_processing' => 0,
|
||||
])
|
||||
->setDefaultValue('')
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'above',
|
||||
'type' => 'string',
|
||||
'weight' => -4,
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textfield',
|
||||
'weight' => -4,
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setDisplayConfigurable('view', TRUE)
|
||||
->setRequired(TRUE);
|
||||
|
||||
$fields['status'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Publishing status'))
|
||||
->setDescription(t('A boolean indicating whether the Chutier is published.'))
|
||||
->setDefaultValue(TRUE)
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'boolean_checkbox',
|
||||
'weight' => -3,
|
||||
]);
|
||||
|
||||
$fields['created'] = BaseFieldDefinition::create('created')
|
||||
->setLabel(t('Created'))
|
||||
->setDescription(t('The time that the entity was created.'));
|
||||
|
||||
$fields['changed'] = BaseFieldDefinition::create('changed')
|
||||
->setLabel(t('Changed'))
|
||||
->setDescription(t('The time that the entity was last edited.'));
|
||||
|
||||
$fields['documents'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Documents'))
|
||||
->setDescription(t('Documents from collection.'))
|
||||
->setSetting('target_type', 'node')
|
||||
->setSetting('handler', 'default')
|
||||
// TODO: check node content type by settings @see readme
|
||||
->setSetting('handler_settings',['target_bundles'=>['enregistrement'=>'enregistrement']] )
|
||||
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
|
||||
->setDisplayOptions('view', array(
|
||||
'label' => 'hidden',
|
||||
'type' => 'enregistrement',
|
||||
'weight' => 0,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
'weight' => 5,
|
||||
'settings' => array(
|
||||
'match_operator' => 'CONTAINS',
|
||||
'size' => '60',
|
||||
'autocomplete_type' => 'tags',
|
||||
'placeholder' => '',
|
||||
),
|
||||
))
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setDisplayConfigurable('view', TRUE);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getUserChutiersContents($uid){
|
||||
// TODO: use query if we use more than one chutier
|
||||
// $query = \Drupal::entityQuery('chutier')
|
||||
// ->condition('user_id', $uid);
|
||||
//
|
||||
// $chutiers_nids = $query->execute();
|
||||
// $chutiers = entity_load_multiple('chutier', $chutiers_nids);
|
||||
//
|
||||
// $contents = array();
|
||||
// foreach ($chutiers as $id => $chutier) {
|
||||
// $contents[$id] = array_column($chutier->documents->getValue(), 'target_id');
|
||||
// }
|
||||
|
||||
/** @var UserDataInterface $userData */
|
||||
$userData = \Drupal::service('user.data');
|
||||
$default_chutier_id = $userData->get('edlp_studio', $uid, 'default_chutier');
|
||||
if($chutier = entity_load('chutier', $default_chutier_id)){
|
||||
return array_column($chutier->documents->getValue(), 'target_id');
|
||||
}else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getActionsUrl($id, $uid){
|
||||
$contents = self::getUserChutiersContents($uid);
|
||||
// dpm($contents);
|
||||
if(array_search($id, $contents) === false){
|
||||
$action = 'add';
|
||||
}else{
|
||||
$action = 'remove';
|
||||
}
|
||||
$args = array(
|
||||
'action'=>$action,
|
||||
'id'=>$id
|
||||
);
|
||||
$url = Url::fromRoute('edlp_studio.chutier_controller_ajax_add_content', $args, array(
|
||||
'attributes' => array(
|
||||
'class' => ['chutier-icon','chutier-link','chutier-ajax-link'],
|
||||
'action' => $action,
|
||||
'target_id' => $id,
|
||||
)
|
||||
));
|
||||
return $url;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
use Drupal\user\EntityOwnerInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Chutier entities.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
interface ChutierInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
|
||||
/**
|
||||
* Gets the Chutier name.
|
||||
*
|
||||
* @return string
|
||||
* Name of the Chutier.
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Sets the Chutier name.
|
||||
*
|
||||
* @param string $name
|
||||
* The Chutier name.
|
||||
*
|
||||
* @return \Drupal\edlp_studio\Entity\ChutierInterface
|
||||
* The called Chutier entity.
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Gets the Chutier creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the Chutier.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
/**
|
||||
* Sets the Chutier creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The Chutier creation timestamp.
|
||||
*
|
||||
* @return \Drupal\edlp_studio\Entity\ChutierInterface
|
||||
* The called Chutier entity.
|
||||
*/
|
||||
public function setCreatedTime($timestamp);
|
||||
|
||||
/**
|
||||
* Returns the Chutier published status indicator.
|
||||
*
|
||||
* Unpublished Chutier are only visible to restricted users.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the Chutier is published.
|
||||
*/
|
||||
public function isPublished();
|
||||
|
||||
/**
|
||||
* Sets the published status of a Chutier.
|
||||
*
|
||||
* @param bool $published
|
||||
* TRUE to set this Chutier to published, FALSE to set it to unpublished.
|
||||
*
|
||||
* @return \Drupal\edlp_studio\Entity\ChutierInterface
|
||||
* The called Chutier entity.
|
||||
*/
|
||||
public function setPublished($published);
|
||||
|
||||
/**
|
||||
* get the contents in user's chutiers
|
||||
*
|
||||
* @param int $uid
|
||||
* user id
|
||||
*
|
||||
* @return array
|
||||
* associative array of contents by chutiers
|
||||
*
|
||||
*/
|
||||
public static function getUserChutiersContents($uid);
|
||||
|
||||
|
||||
/**
|
||||
* get the contents in user's chutiers
|
||||
*
|
||||
* @param int $id
|
||||
* content id
|
||||
*
|
||||
* @param int $uid
|
||||
* user id
|
||||
*
|
||||
* @return Drupal\Core\Url
|
||||
* depending on action is add or remove
|
||||
*
|
||||
*/
|
||||
public static function getActionsURL($id, $uid);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Entity;
|
||||
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides Views data for Chutier entities.
|
||||
*/
|
||||
class ChutierViewsData extends EntityViewsData {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewsData() {
|
||||
$data = parent::getViewsData();
|
||||
|
||||
// Additional information for Views integration, such as table joins, can be
|
||||
// put here.
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityChangedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\user\UserInterface;
|
||||
|
||||
/**
|
||||
* Defines the Composition entity.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "composition",
|
||||
* label = @Translation("Composition"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
|
||||
* "list_builder" = "Drupal\edlp_studio\CompositionListBuilder",
|
||||
* "views_data" = "Drupal\edlp_studio\Entity\CompositionViewsData",
|
||||
*
|
||||
* "form" = {
|
||||
* "default" = "Drupal\edlp_studio\Form\CompositionForm",
|
||||
* "add" = "Drupal\edlp_studio\Form\CompositionForm",
|
||||
* "edit" = "Drupal\edlp_studio\Form\CompositionForm",
|
||||
* "delete" = "Drupal\edlp_studio\Form\CompositionDeleteForm",
|
||||
* },
|
||||
* "access" = "Drupal\edlp_studio\CompositionAccessControlHandler",
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\edlp_studio\CompositionHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* base_table = "composition",
|
||||
* admin_permission = "administer composition entities",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "name",
|
||||
* "uuid" = "uuid",
|
||||
* "uid" = "user_id",
|
||||
* "langcode" = "langcode",
|
||||
* "status" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "canonical" = "/composition/{composition}",
|
||||
* "add-form" = "/composition/add",
|
||||
* "edit-form" = "/composition/{composition}/edit",
|
||||
* "delete-form" = "/composition/{composition}/delete",
|
||||
* "collection" = "/admin/structure/studio/composition",
|
||||
* },
|
||||
* field_ui_base_route = "composition.settings"
|
||||
* )
|
||||
*/
|
||||
class Composition extends ContentEntityBase implements CompositionInterface {
|
||||
|
||||
use EntityChangedTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
|
||||
parent::preCreate($storage_controller, $values);
|
||||
$values += [
|
||||
'user_id' => \Drupal::currentUser()->id(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName() {
|
||||
return $this->get('name')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setName($name) {
|
||||
$this->set('name', $name);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCreatedTime() {
|
||||
return $this->get('created')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setCreatedTime($timestamp) {
|
||||
$this->set('created', $timestamp);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOwner() {
|
||||
return $this->get('user_id')->entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOwnerId() {
|
||||
return $this->get('user_id')->target_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOwnerId($uid) {
|
||||
$this->set('user_id', $uid);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setOwner(UserInterface $account) {
|
||||
$this->set('user_id', $account->id());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isPublished() {
|
||||
return (bool) $this->getEntityKey('status');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setPublished($published) {
|
||||
$this->set('status', $published ? TRUE : FALSE);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Authored by'))
|
||||
->setDescription(t('The user ID of author of the Composition entity.'))
|
||||
->setRevisionable(TRUE)
|
||||
->setSetting('target_type', 'user')
|
||||
->setSetting('handler', 'default')
|
||||
->setTranslatable(TRUE)
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'author',
|
||||
'weight' => 0,
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
'weight' => 5,
|
||||
'settings' => [
|
||||
'match_operator' => 'CONTAINS',
|
||||
'size' => '60',
|
||||
'autocomplete_type' => 'tags',
|
||||
'placeholder' => '',
|
||||
],
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setDisplayConfigurable('view', TRUE);
|
||||
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Name'))
|
||||
->setDescription(t('The name of the Composition entity.'))
|
||||
->setSettings([
|
||||
'max_length' => 50,
|
||||
'text_processing' => 0,
|
||||
])
|
||||
->setDefaultValue('')
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'above',
|
||||
'type' => 'string',
|
||||
'weight' => -4,
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textfield',
|
||||
'weight' => -4,
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setDisplayConfigurable('view', TRUE)
|
||||
->setRequired(TRUE);
|
||||
|
||||
$fields['status'] = BaseFieldDefinition::create('boolean')
|
||||
->setLabel(t('Publishing status'))
|
||||
->setDescription(t('A boolean indicating whether the Composition is published.'))
|
||||
->setDefaultValue(TRUE)
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'boolean_checkbox',
|
||||
'weight' => -3,
|
||||
]);
|
||||
|
||||
$fields['created'] = BaseFieldDefinition::create('created')
|
||||
->setLabel(t('Created'))
|
||||
->setDescription(t('The time that the entity was created.'));
|
||||
|
||||
$fields['changed'] = BaseFieldDefinition::create('changed')
|
||||
->setLabel(t('Changed'))
|
||||
->setDescription(t('The time that the entity was last edited.'));
|
||||
|
||||
$fields['documents'] = BaseFieldDefinition::create('entity_reference')
|
||||
->setLabel(t('Documents'))
|
||||
->setDescription(t('Documents from collection.'))
|
||||
->setSetting('target_type', 'node')
|
||||
->setSetting('handler', 'default')
|
||||
->setSetting('handler_settings',['target_bundles'=>['enregistrement'=>'enregistrement']] )
|
||||
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
|
||||
->setDisplayOptions('view', array(
|
||||
'label' => 'hidden',
|
||||
'type' => 'enregistrement',
|
||||
'weight' => 0,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
'weight' => 5,
|
||||
'settings' => array(
|
||||
'match_operator' => 'CONTAINS',
|
||||
'size' => '60',
|
||||
'autocomplete_type' => 'tags',
|
||||
'placeholder' => '',
|
||||
),
|
||||
))
|
||||
->setDisplayConfigurable('form', TRUE)
|
||||
->setDisplayConfigurable('view', TRUE);
|
||||
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityChangedInterface;
|
||||
use Drupal\user\EntityOwnerInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface for defining Composition entities.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
interface CompositionInterface extends ContentEntityInterface, EntityChangedInterface, EntityOwnerInterface {
|
||||
|
||||
// Add get/set methods for your configuration properties here.
|
||||
|
||||
/**
|
||||
* Gets the Composition name.
|
||||
*
|
||||
* @return string
|
||||
* Name of the Composition.
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Sets the Composition name.
|
||||
*
|
||||
* @param string $name
|
||||
* The Composition name.
|
||||
*
|
||||
* @return \Drupal\edlp_studio\Entity\CompositionInterface
|
||||
* The called Composition entity.
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Gets the Composition creation timestamp.
|
||||
*
|
||||
* @return int
|
||||
* Creation timestamp of the Composition.
|
||||
*/
|
||||
public function getCreatedTime();
|
||||
|
||||
/**
|
||||
* Sets the Composition creation timestamp.
|
||||
*
|
||||
* @param int $timestamp
|
||||
* The Composition creation timestamp.
|
||||
*
|
||||
* @return \Drupal\edlp_studio\Entity\CompositionInterface
|
||||
* The called Composition entity.
|
||||
*/
|
||||
public function setCreatedTime($timestamp);
|
||||
|
||||
/**
|
||||
* Returns the Composition published status indicator.
|
||||
*
|
||||
* Unpublished Composition are only visible to restricted users.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the Composition is published.
|
||||
*/
|
||||
public function isPublished();
|
||||
|
||||
/**
|
||||
* Sets the published status of a Composition.
|
||||
*
|
||||
* @param bool $published
|
||||
* TRUE to set this Composition to published, FALSE to set it to unpublished.
|
||||
*
|
||||
* @return \Drupal\edlp_studio\Entity\CompositionInterface
|
||||
* The called Composition entity.
|
||||
*/
|
||||
public function setPublished($published);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Entity;
|
||||
|
||||
use Drupal\views\EntityViewsData;
|
||||
|
||||
/**
|
||||
* Provides Views data for Composition entities.
|
||||
*/
|
||||
class CompositionViewsData extends EntityViewsData {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getViewsData() {
|
||||
$data = parent::getViewsData();
|
||||
|
||||
// Additional information for Views integration, such as table joins, can be
|
||||
// put here.
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityDeleteForm;
|
||||
|
||||
/**
|
||||
* Provides a form for deleting Chutier entities.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
class ChutierDeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form controller for Chutier edit forms.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
class ChutierForm extends ContentEntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
/* @var $entity \Drupal\edlp_studio\Entity\Chutier */
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
$entity = $this->entity;
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$entity = $this->entity;
|
||||
|
||||
$status = parent::save($form, $form_state);
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Chutier.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Chutier.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirect('entity.chutier.canonical', ['chutier' => $entity->id()]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class ChutierSettingsForm.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
class ChutierSettingsForm extends FormBase {
|
||||
|
||||
/**
|
||||
* Returns a unique string identifying the form.
|
||||
*
|
||||
* @return string
|
||||
* The unique string identifying the form.
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'chutier_settings';
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission handler.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
// Empty implementation of the abstract submit class.
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the settings form for Chutier entities.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*
|
||||
* @return array
|
||||
* Form definition array.
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['chutier_settings']['#markup'] = 'Settings form for Chutier entities. Manage field settings here.';
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityDeleteForm;
|
||||
|
||||
/**
|
||||
* Provides a form for deleting Composition entities.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
class CompositionDeleteForm extends ContentEntityDeleteForm {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Form;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form controller for Composition edit forms.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
class CompositionForm extends ContentEntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
/* @var $entity \Drupal\edlp_studio\Entity\Composition */
|
||||
$form = parent::buildForm($form, $form_state);
|
||||
|
||||
$entity = $this->entity;
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$entity = $this->entity;
|
||||
|
||||
$status = parent::save($form, $form_state);
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Composition.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Composition.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
}
|
||||
$form_state->setRedirect('entity.composition.canonical', ['composition' => $entity->id()]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Form;
|
||||
|
||||
use Drupal\Core\Form\FormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class CompositionSettingsForm.
|
||||
*
|
||||
* @ingroup edlp_studio
|
||||
*/
|
||||
class CompositionSettingsForm extends FormBase {
|
||||
|
||||
/**
|
||||
* Returns a unique string identifying the form.
|
||||
*
|
||||
* @return string
|
||||
* The unique string identifying the form.
|
||||
*/
|
||||
public function getFormId() {
|
||||
return 'composition_settings';
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission handler.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state) {
|
||||
// Empty implementation of the abstract submit class.
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the settings form for Composition entities.
|
||||
*
|
||||
* @param array $form
|
||||
* An associative array containing the structure of the form.
|
||||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*
|
||||
* @return array
|
||||
* Form definition array.
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['composition_settings']['#markup'] = 'Settings form for Composition entities. Manage field settings here.';
|
||||
return $form;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\edlp_studio\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Session\AccountProxy;
|
||||
use Drupal\Core\Session\AccountProxyInterface;
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\Core\Url;
|
||||
|
||||
/**
|
||||
* Provides a 'StudioLinkBlock' block.
|
||||
*
|
||||
* @Block(
|
||||
* id = "edlp_studio_link_block",
|
||||
* admin_label = @Translation("Studio link block"),
|
||||
* )
|
||||
*/
|
||||
class StudioLinkBlock extends BlockBase implements ContainerFactoryPluginInterface{
|
||||
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
// Instantiates this form class.
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('current_user')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $configuration
|
||||
* @param string $plugin_id
|
||||
* @param mixed $plugin_definition
|
||||
* @param \Drupal\Core\Session\AccountProxyInterface $account
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountProxyInterface $account) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->user = $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
$build = [];
|
||||
if($this->user->id()){
|
||||
$url = Url::fromRoute('edlp_studio.studio_ui');
|
||||
$build['edlp_studio_link_block'] = array(
|
||||
'#title' => "Studio",
|
||||
'#type' => 'link',
|
||||
'#url' => $url,
|
||||
'#options'=>array(
|
||||
'attributes' => array(
|
||||
'data-drupal-link-system-path' => $url->getInternalPath(),
|
||||
'class' => array('ajax-link'),
|
||||
'alt' => t('The studio displays your bookmarked sounds. You can save them and create your own playlists'),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
return $build;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
{#
|
||||
/**
|
||||
* @file chutier.html.twig
|
||||
* Default theme implementation to present Chutier data.
|
||||
*
|
||||
* This template is used when viewing Chutier pages.
|
||||
*
|
||||
*
|
||||
* Available variables:
|
||||
* - content: A list of content items. Use 'content' to print all content, or
|
||||
* - attributes: HTML attributes for the container element.
|
||||
*
|
||||
* @see template_preprocess_chutier()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes.addClass('chutier') }}>
|
||||
{% if content %}
|
||||
{{- content -}}
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -0,0 +1,20 @@
|
||||
{#
|
||||
/**
|
||||
* @file composition.html.twig
|
||||
* Default theme implementation to present Composition data.
|
||||
*
|
||||
* This template is used when viewing Composition pages.
|
||||
*
|
||||
*
|
||||
* Available variables:
|
||||
* - content: A list of content items. Use 'content' to print all content, or
|
||||
* - attributes: HTML attributes for the container element.
|
||||
*
|
||||
* @see template_preprocess_composition()
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
<div{{ attributes }}>
|
||||
{{ content }}
|
||||
</div>
|
||||
@@ -0,0 +1,6 @@
|
||||
<div class="chutier_ui">
|
||||
<h2>{{ title }}</h2>
|
||||
<section class="documents">
|
||||
{{ documents }}
|
||||
</section>
|
||||
</div>
|
||||
@@ -0,0 +1,17 @@
|
||||
<div class="composition_ui">
|
||||
<h2>{{ title }}</h2>
|
||||
<div class="wrapper">
|
||||
<section class='compositions-list'>
|
||||
{{ compositions }}
|
||||
</section>
|
||||
<section class="composer">
|
||||
<header>
|
||||
{{ composer_header }}
|
||||
</header>
|
||||
{{ composition }}
|
||||
<section class="actions">
|
||||
{{ composer_actions }}
|
||||
</section>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1 @@
|
||||
{{ compositions }}
|
||||
@@ -0,0 +1,4 @@
|
||||
<div id="studio-ui">
|
||||
{{ chutier_ui }}
|
||||
{{ composition_ui }}
|
||||
</div>
|
||||
Reference in New Issue
Block a user