updated custom modules codes for d9
This commit is contained in:
@@ -121,7 +121,7 @@ class ChutierController extends ControllerBase {
|
||||
}
|
||||
|
||||
private function validateNewDoc($id){
|
||||
$node = entity_load('node', $id);
|
||||
$node = \Drupal::entityTypeManager()->getStorage('node')->load($id);
|
||||
if($node){
|
||||
// TODO: get node bundle by settings (@see readme)
|
||||
if($node->getType() == 'enregistrement'){
|
||||
@@ -149,7 +149,7 @@ class ChutierController extends ControllerBase {
|
||||
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);
|
||||
$this->chutier = \Drupal::entityTypeManager()->getStorage('chutier')->load($default_chutier_id);
|
||||
// if default chutier does not exists, create, save and record it
|
||||
if(!$this->chutier){
|
||||
$this->createDefaultChutier();
|
||||
@@ -169,7 +169,7 @@ class ChutierController extends ControllerBase {
|
||||
'status' => TRUE,
|
||||
'name' => t('Default'),
|
||||
);
|
||||
$this->chutier = entity_create('chutier', $chutier);
|
||||
$this->chutier = \Drupal::entityTypeManager()->getStorage('chutier')->create($chutier);
|
||||
$this->chutier->save();
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ class CompositionController extends ControllerBase {
|
||||
'status' => TRUE,
|
||||
'name' => $name,
|
||||
);
|
||||
$this->compo = entity_create('composition', $compo);
|
||||
$this->compo = \Drupal::entityTypeManager()->getStorage('composition')->create($compo);
|
||||
$this->compo->save();
|
||||
}
|
||||
|
||||
@@ -181,11 +181,11 @@ class CompositionController extends ControllerBase {
|
||||
}
|
||||
|
||||
private function openComposition($cid){
|
||||
$this->compo = entity_load('composition', $cid);
|
||||
$this->compo = \Drupal::entityTypeManager()->getStorage('composition')->load($cid);
|
||||
}
|
||||
|
||||
private function saveComposition($cid, $name = "", $new_documents = array()){
|
||||
$this->compo = entity_load('composition', $cid);
|
||||
$this->compo = \Drupal::entityTypeManager()->getStorage('composition')->load($cid);
|
||||
if($name != ""){
|
||||
$this->compo->setName($name);
|
||||
}
|
||||
@@ -201,7 +201,7 @@ class CompositionController extends ControllerBase {
|
||||
|
||||
|
||||
private function deleteComposition($cid){
|
||||
$this->compo = entity_load('composition', $cid);
|
||||
$this->compo = \Drupal::entityTypeManager()->getStorage('composition')->load($cid);
|
||||
$this->compo->delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ class StudioUIController extends ControllerBase {
|
||||
$documents_nids = Chutier::getUserChutiersContents($this->user->id());
|
||||
// dpm($documents_nids);
|
||||
|
||||
$documents = entity_load_multiple('node', $documents_nids);
|
||||
$documents = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($documents_nids);
|
||||
|
||||
// build content renderable array
|
||||
$chutier_ui = array(
|
||||
@@ -153,6 +153,7 @@ class StudioUIController extends ControllerBase {
|
||||
private function buildCompostionsList(){
|
||||
// get compositions
|
||||
$query = \Drupal::entityQuery('composition')
|
||||
->accessCheck(TRUE)
|
||||
->condition('user_id', $this->user->id());
|
||||
|
||||
$compos_ids = $query->execute();
|
||||
@@ -160,7 +161,7 @@ class StudioUIController extends ControllerBase {
|
||||
|
||||
if(!count($compos_ids)){
|
||||
// create default compos
|
||||
$def_compos = \Drupal::entityManager()
|
||||
$def_compos = \Drupal::entityTypeManager()
|
||||
->getStorage('composition')
|
||||
->create(array(
|
||||
'name' => 'composition',
|
||||
@@ -171,7 +172,7 @@ class StudioUIController extends ControllerBase {
|
||||
$compos_ids = array($def_compos->id());
|
||||
}
|
||||
|
||||
$compos = entity_load_multiple('composition', $compos_ids);
|
||||
$compos = \Drupal::entityTypeManager()->getStorage('composition')->loadMultiple($compos_ids);
|
||||
|
||||
$createurl = Url::fromRoute('edlp_studio.composition_controller_action_ajax', ['action' => 'create'], ['absolute' => TRUE]);
|
||||
|
||||
@@ -185,13 +186,14 @@ class StudioUIController extends ControllerBase {
|
||||
private function getLastCompo(){
|
||||
// just get the last compositions
|
||||
$query = \Drupal::entityQuery('composition')
|
||||
->accessCheck(TRUE)
|
||||
->condition('user_id', $this->user->id())
|
||||
->range(0,1)
|
||||
->sort('created', 'DESC');
|
||||
|
||||
$compos_id = $query->execute();
|
||||
if(count($compos_id)){
|
||||
$lastcompo = entity_load('composition', array_pop($compos_id));
|
||||
$lastcompo = \Drupal::entityTypeManager()->getStorage('composition')->load(array_pop($compos_id));
|
||||
}else{
|
||||
$lastcompo = null;
|
||||
}
|
||||
|
||||
@@ -247,10 +247,11 @@ class Chutier extends ContentEntityBase implements ChutierInterface {
|
||||
public static function getUserChutiersContents($uid){
|
||||
// TODO: use query if we use more than one chutier
|
||||
// $query = \Drupal::entityQuery('chutier')
|
||||
// ->accessCheck(TRUE)
|
||||
// ->condition('user_id', $uid);
|
||||
//
|
||||
// $chutiers_nids = $query->execute();
|
||||
// $chutiers = entity_load_multiple('chutier', $chutiers_nids);
|
||||
// $chutiers = \Drupal::entityTypeManager()->getStorage('chutier')->loadMultiple($chutiers_nids);
|
||||
//
|
||||
// $contents = array();
|
||||
// foreach ($chutiers as $id => $chutier) {
|
||||
@@ -260,7 +261,7 @@ class Chutier extends ContentEntityBase implements ChutierInterface {
|
||||
/** @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)){
|
||||
if($chutier = \Drupal::entityTypeManager()->getStorage('chutier')->load($default_chutier_id)){
|
||||
return array_column($chutier->documents->getValue(), 'target_id');
|
||||
}else{
|
||||
return array();
|
||||
|
||||
@@ -34,13 +34,13 @@ class ChutierForm extends ContentEntityForm {
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Chutier.', [
|
||||
\Drupal::messenger()->addMessage($this->t('Created the %label Chutier.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Chutier.', [
|
||||
\Drupal::messenger()->addMessage($this->t('Saved the %label Chutier.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
}
|
||||
|
||||
@@ -34,13 +34,13 @@ class CompositionForm extends ContentEntityForm {
|
||||
|
||||
switch ($status) {
|
||||
case SAVED_NEW:
|
||||
drupal_set_message($this->t('Created the %label Composition.', [
|
||||
\Drupal::messenger()->addMessage($this->t('Created the %label Composition.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
break;
|
||||
|
||||
default:
|
||||
drupal_set_message($this->t('Saved the %label Composition.', [
|
||||
\Drupal::messenger()->addMessage($this->t('Saved the %label Composition.', [
|
||||
'%label' => $entity->label(),
|
||||
]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user