home is working now like the productions home page

This commit is contained in:
Bachir Soussi Chiadmi
2018-03-28 11:44:36 +02:00
parent 0477bee1d5
commit 0bf219cf35
15 changed files with 411 additions and 150 deletions
@@ -1,81 +0,0 @@
<?php
use Drupal\Core\Url;
function template_preprocess_edlp_home(&$vars){
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
// dpm($vars);
// render the presentation column
$vars["presentation"] = array(
"#type"=>"container",
"pres"=>$view_builder->view($vars["presentation_node"], 'default'),
"link"=> array(
'#title' => t('Visiter la collection sonore.'),
'#type' => 'link',
'#url' => Url::fromRoute('<front>', [], array(
'attributes' => array(
'class' => ['corpus-link', 'ajax-link']
)
))
)
);
// render the last fil column
$vars["last_fil"] = array(
"#type" => "container",
// 'fil' => $view_builder->view($vars['last_fil_node'], 'teaser'),
'title'=> array("#markup" => "<h2 class='title'>Dernier Fil</h2>"),
'fil' => $vars['last_fil_node'],
// 'links' => array(
// '#theme' => 'item_list',
// '#items' => array(
// 'link_all' => array(
// '#title' => t("Voir tous les fils de l'EP."),
// '#type' => 'link',
// '#url' => Url::fromRoute('edlp_fils.fils', [], array(
// 'attributes' => array(
// 'class' => ['fils-link', 'ajax-link']
// )
// ))
// ),
// // TODO: link posdcast fils
// 'link_podcast' => array(
// '#title' => t("S'abonner au podcast des fils."),
// '#type' => 'link',
// '#url' => Url::fromRoute('<front>', [], array(
// 'attributes' => array(
// 'class' => ['fils-link']
// )
// ))
// )
// )
// )
);
// render the last production column
$vars["last_production"] = array(
'#type' => 'container',
'prod' => $view_builder->view($vars['last_production_node'], 'teaser'),
'link'=> array(
'#title' => t('Voir toutes les productions.'),
'#type' => 'link',
'#url' => Url::fromRoute('edlp_productions.productions', [], array(
'attributes' => array(
'class' => ['productions-link', 'ajax-link']
)
))
)
);
// render the next events of agenda as list
$agenda = array (
'#theme' => 'item_list',
'#items' => [],
);
foreach($vars['agenda_items'] as $node){
$agenda['#items'][] = $view_builder->view($node, 'teaser');
}
$vars['agenda'] = render($agenda);
}
@@ -17,11 +17,12 @@ function edlp_home_theme($existing, $type, $theme, $path) {
return array(
'edlp_home' => array(
// 'render element' => '',
'file' => 'edlp_home.inc',
'file' => 'includes/edlp_home.inc',
'variables' => array(
'presentation_node' => NULL,
'last_fil_node' => NULL,
'last_production_node' => NULL,
// 'presentation_node' => NULL,
// 'last_fil_node' => NULL,
// 'last_production_node' => NULL,
'promoted_nodes' => array(),
'agenda_items' => NULL
),
),
@@ -0,0 +1,105 @@
<?php
use Drupal\Core\Url;
function template_preprocess_edlp_home(&$vars){
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
// dpm($vars);
// render the promoted_nodes
foreach($vars['promoted_nodes'] as $node){
if($node->hasField('field_view_mode')){
switch($node->get('field_view_mode')->value){
case "1":
$vm = "image_2_columns";
break;
case "2":
$vm = "image_1_columns";
break;
case "3":
$vm = "text_1_column";
break;
};
}else{
$vm = 'default';
}
$vars['nodes'][] = array(
'vm'=>$vm,
'build'=>$view_builder->view($node, $vm)
);
}
// render the presentation column
// $vars["presentation"] = array(
// "#type"=>"container",
// "pres"=>$view_builder->view($vars["presentation_node"], 'default'),
// "link"=> array(
// '#title' => t('Visiter la collection sonore.'),
// '#type' => 'link',
// '#url' => Url::fromRoute('<front>', [], array(
// 'attributes' => array(
// 'class' => ['corpus-link', 'ajax-link']
// )
// ))
// )
// );
// render the last fil column
// $vars["last_fil"] = array(
// "#type" => "container",
// // 'fil' => $view_builder->view($vars['last_fil_node'], 'teaser'),
// 'title'=> array("#markup" => "<h2 class='title'>Dernier Fil</h2>"),
// 'fil' => $vars['last_fil_node'],
// // 'links' => array(
// // '#theme' => 'item_list',
// // '#items' => array(
// // 'link_all' => array(
// // '#title' => t("Voir tous les fils de l'EP."),
// // '#type' => 'link',
// // '#url' => Url::fromRoute('edlp_fils.fils', [], array(
// // 'attributes' => array(
// // 'class' => ['fils-link', 'ajax-link']
// // )
// // ))
// // ),
// // // TODO: link posdcast fils
// // 'link_podcast' => array(
// // '#title' => t("S'abonner au podcast des fils."),
// // '#type' => 'link',
// // '#url' => Url::fromRoute('<front>', [], array(
// // 'attributes' => array(
// // 'class' => ['fils-link']
// // )
// // ))
// // )
// // )
// // )
// );
// render the last production column
// $vars["last_production"] = array(
// '#type' => 'container',
// 'prod' => $view_builder->view($vars['last_production_node'], 'teaser'),
// 'link'=> array(
// '#title' => t('Voir toutes les productions.'),
// '#type' => 'link',
// '#url' => Url::fromRoute('edlp_productions.productions', [], array(
// 'attributes' => array(
// 'class' => ['productions-link', 'ajax-link']
// )
// ))
// )
// );
// render the next events of agenda as list
$agenda = array (
'#theme' => 'item_list',
'#items' => [],
);
foreach($vars['agenda_items'] as $node){
$agenda['#items'][] = $view_builder->view($node, 'teaser');
}
$vars['agenda'] = render($agenda);
}
@@ -16,18 +16,36 @@ class HomeController extends ControllerBase {
*/
public function home() {
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
// $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$contents = array("#theme"=>'edlp_home');
// presentation
// first get static pages
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('nid', 12242);
// TODO: présentation nid should be a setting
->condition('field_afficher_en_page_d_acceuil', 1)
->condition('type', 'static');
$pres_nid = $query->execute();
$contents["#presentation_node"] = entity_load('node', array_pop($pres_nid));
$promoted_nids = $query->execute();
$contents["#promoted_nodes"] = entity_load_multiple('node', $promoted_nids);
// then get production pages
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('field_afficher_en_page_d_acceuil', 1)
->condition('type', 'page');
$promoted_nids = $query->execute();
$contents["#promoted_nodes"] += entity_load_multiple('node', $promoted_nids);
// presentation
// $query = \Drupal::entityQuery('node')
// ->condition('status', 1)
// ->condition('nid', 12242);
// // TODO: présentation nid should be a setting
//
// $pres_nid = $query->execute();
// $contents["#presentation_node"] = entity_load('node', array_pop($pres_nid));
// last fil
// $query = \Drupal::entityQuery('node')
@@ -38,19 +56,19 @@ class HomeController extends ControllerBase {
//
// $fil = $query->execute();
// $contents["#last_fil_node"] = entity_load('node', array_pop($fil));
$contents["#last_fil_node"] = array('#markup'=>'En développement.');
// $contents["#last_fil_node"] = array('#markup'=>'En développement.');
// last production
$query = \Drupal::entityQuery('node')
->condition('status', 1)
->condition('type', 'page')
->condition('field_page_type', array('1168'), 'NOT IN')
->sort('created', 'DESC')
->range(0,1);
$prod = $query->execute();
$contents["#last_production_node"] = entity_load('node', array_pop($prod));
// $query = \Drupal::entityQuery('node')
// ->condition('status', 1)
// ->condition('type', 'page')
// ->condition('field_page_type', array('1168'), 'NOT IN')
// ->sort('created', 'DESC')
// ->range(0,1);
//
// $prod = $query->execute();
// $contents["#last_production_node"] = entity_load('node', array_pop($prod));
// agenda
$now = new DrupalDateTime('now');
@@ -1,4 +1,8 @@
{{ presentation }}
{{ last_fil }}
{{ last_production }}
{# presentation #}
{# last_fil #}
{# last_production #}
{% for node in nodes %}
{{ node.build }}
{% endfor %}
{{ agenda }}
@@ -37,6 +37,25 @@ function edlptheme_form_user_login_form_alter(&$form, FormStateInterface $form_s
unset($form['pass']['#title']);
}
function edlptheme_preprocess_edlp_home(&$vars){
foreach($vars['nodes'] as &$node){
switch($node['vm']){
case "image_2_columns":
$cols = 4;
break;
case "image_1_columns":
$cols = 2;
break;
case "text_1_column":
$cols = 2;
break;
default:
$cols = 2;
};
$node['cols'] = $cols;
}
}
function edlptheme_preprocess_edlp_productions(&$vars){
foreach($vars['nodes'] as &$node){
switch($node['vm']){
@@ -1,3 +1,4 @@
{#
<div class="presentation col col-4">
<div class="wrapper">
{{ presentation }}
@@ -13,6 +14,16 @@
{{ last_production }}
</div>
</div>
#}
{% for node in nodes %}
<div class="col col-{{ node.cols }}">
<div class="wrapper">
{{ node.build }}
</div>
</div>
{% endfor %}
<div class="agenda col col-2">
<div class="wrapper">
{{ agenda }}
@@ -4,6 +4,7 @@ status: true
dependencies:
config:
- field.field.node.page.body
- field.field.node.page.field_afficher_en_page_d_acceuil
- field.field.node.page.field_documents_lies
- field.field.node.page.field_page_type
- field.field.node.page.field_son
@@ -17,7 +18,6 @@ dependencies:
- file
- filefield_sources
- image
- path
- text
- workflow
third_party_settings:
@@ -68,10 +68,11 @@ third_party_settings:
region: content
group_infos:
children:
- field_page_type
- langcode
- field_afficher_en_page_d_acceuil
- field_view_mode
- field_workflow_generic
- field_page_type
parent_name: group_tabs
weight: 4
format_type: tab
@@ -111,12 +112,13 @@ content:
placeholder: ''
third_party_settings: { }
region: content
created:
type: datetime_timestamp
weight: 3
region: content
settings: { }
field_afficher_en_page_d_acceuil:
weight: 10
settings:
display_label: true
third_party_settings: { }
type: boolean_checkbox
region: content
field_documents_lies:
weight: 124
settings:
@@ -127,7 +129,7 @@ content:
type: entity_reference_autocomplete
region: content
field_page_type:
weight: 3
weight: 14
settings: { }
third_party_settings: { }
type: options_select
@@ -155,7 +157,7 @@ content:
type: file_generic
region: content
field_view_mode:
weight: 5
weight: 12
settings: { }
third_party_settings: { }
type: options_select
@@ -169,14 +171,14 @@ content:
type: image_image
region: content
field_workflow_generic:
weight: 6
weight: 13
settings: { }
third_party_settings: { }
type: workflow_default
region: content
langcode:
type: language_select
weight: 4
weight: 9
region: content
settings:
include_locked: true
@@ -189,26 +191,6 @@ content:
third_party_settings: { }
type: string_textfield
region: content
path:
type: path
weight: 6
region: content
settings: { }
third_party_settings: { }
promote:
type: boolean_checkbox
settings:
display_label: true
weight: 5
region: content
third_party_settings: { }
sticky:
type: boolean_checkbox
settings:
display_label: true
weight: 4
region: content
third_party_settings: { }
title:
type: string_textfield
weight: 0
@@ -217,19 +199,11 @@ content:
size: 60
placeholder: ''
third_party_settings: { }
translation:
weight: 7
region: content
settings: { }
third_party_settings: { }
uid:
type: entity_reference_autocomplete
weight: 2
settings:
match_operator: CONTAINS
size: 60
placeholder: ''
region: content
third_party_settings: { }
hidden:
created: true
path: true
promote: true
status: true
sticky: true
translation: true
uid: true
@@ -4,6 +4,7 @@ status: true
dependencies:
config:
- field.field.node.static.body
- field.field.node.static.field_afficher_en_page_d_acceuil
- field.field.node.static.field_visuel
- field.field.node.static.field_workflow_generic
- image.style.thumbnail
@@ -47,6 +48,7 @@ third_party_settings:
group_infos:
children:
- langcode
- field_afficher_en_page_d_acceuil
- field_workflow_generic
parent_name: group_tabs
weight: 14
@@ -73,6 +75,13 @@ content:
placeholder: ''
third_party_settings: { }
region: content
field_afficher_en_page_d_acceuil:
weight: 2
settings:
display_label: true
third_party_settings: { }
type: boolean_checkbox
region: content
field_visuel:
weight: 3
settings:
@@ -82,7 +91,7 @@ content:
type: image_image
region: content
field_workflow_generic:
weight: 2
weight: 3
settings: { }
third_party_settings: { }
type: workflow_default
@@ -4,6 +4,7 @@ status: true
dependencies:
config:
- field.field.node.page.body
- field.field.node.page.field_afficher_en_page_d_acceuil
- field.field.node.page.field_documents_lies
- field.field.node.page.field_page_type
- field.field.node.page.field_son
@@ -65,6 +66,7 @@ content:
settings: { }
third_party_settings: { }
hidden:
field_afficher_en_page_d_acceuil: true
field_page_type: true
field_view_mode: true
field_workflow_generic: true
@@ -4,6 +4,7 @@ status: true
dependencies:
config:
- field.field.node.static.body
- field.field.node.static.field_afficher_en_page_d_acceuil
- field.field.node.static.field_visuel
- field.field.node.static.field_workflow_generic
- image.style.large
@@ -39,5 +40,6 @@ content:
settings: { }
third_party_settings: { }
hidden:
field_afficher_en_page_d_acceuil: true
field_workflow_generic: true
langcode: true
@@ -0,0 +1,23 @@
uuid: b2fd8b5b-fad7-46dc-8672-9a2eb27b80be
langcode: fr
status: true
dependencies:
config:
- field.storage.node.field_afficher_en_page_d_acceuil
- node.type.page
id: node.page.field_afficher_en_page_d_acceuil
field_name: field_afficher_en_page_d_acceuil
entity_type: node
bundle: page
label: 'Afficher en page d''acceuil'
description: ''
required: false
translatable: false
default_value:
-
value: 0
default_value_callback: ''
settings:
on_label: Activé
off_label: Désactivé
field_type: boolean
@@ -0,0 +1,23 @@
uuid: ce2f5779-2a03-4ad7-bc4f-2f4c17f0131f
langcode: fr
status: true
dependencies:
config:
- field.storage.node.field_afficher_en_page_d_acceuil
- node.type.static
id: node.static.field_afficher_en_page_d_acceuil
field_name: field_afficher_en_page_d_acceuil
entity_type: node
bundle: static
label: 'Afficher en page d''acceuil'
description: ''
required: false
translatable: false
default_value:
-
value: 0
default_value_callback: ''
settings:
on_label: Activé
off_label: Désactivé
field_type: boolean
@@ -0,0 +1,18 @@
uuid: 8934337f-bc8c-4f59-ae75-d2751ec61db9
langcode: fr
status: true
dependencies:
module:
- node
id: node.field_afficher_en_page_d_acceuil
field_name: field_afficher_en_page_d_acceuil
entity_type: node
type: boolean
settings: { }
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
@@ -4,6 +4,7 @@ status: true
dependencies:
config:
- field.storage.node.body
- field.storage.node.field_afficher_en_page_d_acceuil
- field.storage.node.field_collectionneurs
- field.storage.node.field_date
- field.storage.node.field_description
@@ -1799,6 +1800,71 @@ display:
plugin_id: field
entity_type: node
entity_field: status
field_afficher_en_page_d_acceuil:
id: field_afficher_en_page_d_acceuil
table: node__field_afficher_en_page_d_acceuil
field: field_afficher_en_page_d_acceuil
relationship: none
group_type: group
admin_label: ''
label: 'Afficher en page d''acceuil'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: boolean
settings:
format: yes-no
format_custom_true: ''
format_custom_false: ''
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
title: Production
display_plugin: page
display_title: Production
@@ -1815,6 +1881,7 @@ display:
- user.roles
max-age: -1
tags:
- 'config:field.storage.node.field_afficher_en_page_d_acceuil'
- 'config:field.storage.node.field_page_type'
- 'config:field.storage.node.field_son'
- 'config:field.storage.node.field_view_mode'
@@ -4122,6 +4189,71 @@ display:
plugin_id: field
entity_type: node
entity_field: status
field_afficher_en_page_d_acceuil:
id: field_afficher_en_page_d_acceuil
table: node__field_afficher_en_page_d_acceuil
field: field_afficher_en_page_d_acceuil
relationship: none
group_type: group
admin_label: ''
label: 'Afficher en page d''acceuil'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: boolean
settings:
format: yes-no
format_custom_true: ''
format_custom_false: ''
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
plugin_id: field
title: Static
display_plugin: page
display_title: Static
@@ -4138,5 +4270,6 @@ display:
- user.roles
max-age: -1
tags:
- 'config:field.storage.node.field_afficher_en_page_d_acceuil'
- 'config:field.storage.node.field_visuel'
- 'config:field.storage.node.field_workflow_generic'