ajax loading of edlp studio from custom block link ok

also refactored page layout for better display of footer
This commit is contained in:
Bachir Soussi Chiadmi
2018-03-12 16:55:13 +01:00
parent 294d660d5f
commit 119f89abca
25 changed files with 569 additions and 96 deletions
@@ -6,6 +6,7 @@ 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;
@@ -38,36 +39,69 @@ class StudioUIController extends ControllerBase {
);
}
/**
* Studioui.
* Studio-ui.
*
* @return string
* Return Hello string.
* @return array
* Return renderable array.
*/
public function StudioUI() {
return $this->buildUI();
}
/**
* Studio-ui.
*
* @return array
* Return renderable array.
*/
public function StudioUIJson() {
$renderable = $this->buildUI();
$rendered = render($renderable);
// JSON
$response = new JsonResponse();
$response->setData([
'rendered'=> $rendered,
]);
return $response;
}
public function buildUI(){
// get current user
// done by DependencyInjection of AccountInterface
dpm($this->user->id());
// dpm($this->user->id());
// get his docs in chutier
$docs = Chutier::getUserChutiersContents($this->user->id());
dpm($docs);
$documents_nids = Chutier::getUserChutiersContents($this->user->id());
// dpm($documents_nids);
// TODO: add chutier theme, preprocess, twig template to studio module
// TODO: build content renderable array
$documents = entity_load_multiple('node', $documents_nids);
// build content renderable array
$chutier_ui = array(
"#theme"=>'edlp_chutier_ui',
'#title' => t('Chutier'),
"#document_nodes" => $documents,
);
// TODO: get compositions
// TODO: add compositions theme, preprocess, twig template to studio module
// TODO: build content renderable array
$composition_ui = array(
"#theme"=>'edlp_compostion_ui',
"#title" => t('Composition'),
"#compositions" => array('#markup'=>'TODO : compositions UI'),
);
// TODO: add studio theme, preprocess, twig template to studio module
// TODO: build global studio renderable array
return [
'#type' => 'markup',
'#markup' => $this->t('Implement method: StudioUI')
'#theme' => 'edlp_studio_ui',
'#chutier_ui' => $chutier_ui,
'#composition_ui' => $composition_ui,
];
}
}
@@ -0,0 +1,71 @@
<?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', [], ['absolute' => TRUE]);
$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'),
)
)
);
}
return $build;
}
}