complete refactoring of thematique list display : entityfieldquery + viewmode
This commit is contained in:
@@ -1,21 +1,43 @@
|
||||
<?php
|
||||
|
||||
|
||||
// function clameursmod_panels_pre_render($panel, &$renderer){
|
||||
// dsm($panel, 'panel');
|
||||
// dsm($renderer, 'renderer');
|
||||
//
|
||||
// $node_ctx = $render->display['context'][0]['data'];
|
||||
// dsm($node_ctx, 'node_ctx');
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
// function clameursmod_menu() {
|
||||
// $items['accueil'] = array(
|
||||
// 'title' => '',
|
||||
// 'page callback' => '',
|
||||
// 'page arguments' => array(),
|
||||
// 'access arguments' => array(''),
|
||||
// 'type' => ,
|
||||
// 'file' => ,
|
||||
// );
|
||||
//
|
||||
// return $items;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Implements hook_entity_info_alter().
|
||||
*/
|
||||
function clameursmod_entity_info_alter(&$entity_info) {
|
||||
$entity_info['node']['view modes']['accueil'] = array(
|
||||
'label' => t('Accueil'),
|
||||
'custom settings' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_block_info().
|
||||
*/
|
||||
function clameursmod_block_info() {
|
||||
$blocks['thematiques'] = array(
|
||||
'info' => t('Clameurs thematiques'),
|
||||
'cache' => DRUPAL_NO_CACHE
|
||||
);
|
||||
$blocks['thematiques-anchor-links'] = array(
|
||||
'info' => t('Clameurs thematique anchor links'),
|
||||
'info' => t('Clameurs thematiques anchor links'),
|
||||
'cache' => DRUPAL_NO_CACHE
|
||||
);
|
||||
|
||||
@@ -30,21 +52,80 @@ function clameursmod_block_view($delta = '') {
|
||||
$block = array();
|
||||
|
||||
switch ($delta) {
|
||||
case 'thematiques':
|
||||
$block['subject'] = t('Thématiques');
|
||||
$block['content'] = _clameursmod_thematiques();
|
||||
break;
|
||||
case 'thematiques-anchor-links':
|
||||
$block['subject'] = t('Thématique menu');
|
||||
$block['subject'] = t('Thématiques menu');
|
||||
$block['content'] = _clameursmod_thematiques_anchor_links();
|
||||
break;
|
||||
}
|
||||
return $block;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function clameursmod_theme($existing, $type, $theme, $path) {
|
||||
return array(
|
||||
'thematiques' => array(
|
||||
'render element' => 'element'
|
||||
),
|
||||
'thematiques_anchor_links' => array(
|
||||
'render element' => 'element'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ________ __ _
|
||||
// /_ __/ /_ ___ ____ ___ ____ _/ /_(_)___ ___ _____ _____
|
||||
// / / / __ \/ _ \/ __ `__ \/ __ `/ __/ / __ `/ / / / _ \/ ___/
|
||||
// / / / / / / __/ / / / / / /_/ / /_/ / /_/ / /_/ / __(__ )
|
||||
// /_/ /_/ /_/\___/_/ /_/ /_/\__,_/\__/_/\__, /\__,_/\___/____/
|
||||
// /_/
|
||||
|
||||
function _clameursmod_thematiques(){
|
||||
$query = new EntityFieldQuery();
|
||||
$query
|
||||
->entityCondition('entity_type', 'node')
|
||||
->entityCondition('bundle', 'thematique')
|
||||
->propertyCondition('status', 1)
|
||||
->fieldOrderBy('field_poid', 'value', 'ASC');
|
||||
|
||||
$result = $query->execute();
|
||||
// dsm($result['node'], "result");
|
||||
$nids = array_keys($result['node']);
|
||||
|
||||
$nodes = array();
|
||||
foreach ($nids as $nid) {
|
||||
$nodes[] = node_load($nid);
|
||||
}
|
||||
return theme('thematiques', array("items"=>$nodes));
|
||||
}
|
||||
|
||||
|
||||
function theme_thematiques($vars){
|
||||
$nodes = $vars['items'];
|
||||
$view_mode = "accueil";
|
||||
$entity_view = entity_view('node', $nodes, $view_mode);
|
||||
return render($entity_view);
|
||||
}
|
||||
|
||||
// ___ __
|
||||
// / | ____ _____/ /_ ____ __________
|
||||
// / /| | / __ \/ ___/ __ \/ __ \/ ___/ ___/
|
||||
// / ___ |/ / / / /__/ / / / /_/ / / (__ )
|
||||
// /_/ |_/_/ /_/\___/_/ /_/\____/_/ /____/
|
||||
|
||||
function _clameursmod_thematiques_anchor_links(){
|
||||
$query = new EntityFieldQuery();
|
||||
$query
|
||||
->entityCondition('entity_type', 'node')
|
||||
->entityCondition('bundle', 'thematique')
|
||||
->propertyCondition('status', 1);
|
||||
// ->propertyOrderBy('created', 'DESC');
|
||||
->propertyCondition('status', 1)
|
||||
->fieldOrderBy('field_poid', 'value', 'ASC');
|
||||
|
||||
$result = $query->execute();
|
||||
$nids = array_keys($result['node']);
|
||||
@@ -52,27 +133,31 @@ function _clameursmod_thematiques_anchor_links(){
|
||||
$nodes = [];
|
||||
foreach ($nids as $nid) {
|
||||
$node = node_load($nid);
|
||||
// dsm($node);
|
||||
$alias = drupal_get_path_alias('node/'.$nid);
|
||||
// TODO: get the workflow state ID
|
||||
// get the workflow state ID
|
||||
$current_state = workflow_state_load_single($node->workflow);
|
||||
// dsm($current_state, 'current_state');
|
||||
// $workflow = $current_state->getWorkflow();
|
||||
// dsm($workflow, "workflow");
|
||||
$scheduled_transitions = WorkflowScheduledTransition::load('node', $nid, NULL, 1);
|
||||
$transition = false;
|
||||
if(count($scheduled_transitions)){
|
||||
// dsm($scheduled_transitions, "scheduled_transitions");
|
||||
$transition = $scheduled_transitions[0];
|
||||
}
|
||||
|
||||
$nodes[$nid] = array(
|
||||
"alias"=>$alias,
|
||||
"title"=>$node->title
|
||||
"title"=>$node->title,
|
||||
"wf_sid"=>$node->workflow,
|
||||
"wf_stamp"=> $transition ? $transition->scheduled : false,
|
||||
"wf_state"=>$current_state->getName(),
|
||||
);
|
||||
}
|
||||
return theme('thematiques_anchor_links', array("items"=>$nodes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function clameursmod_theme($existing, $type, $theme, $path) {
|
||||
return array(
|
||||
'thematiques_anchor_links' => array(
|
||||
'render element' => 'element'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function theme_thematiques_anchor_links($vars){
|
||||
$list = array(
|
||||
'items'=>array(),
|
||||
@@ -82,13 +167,22 @@ function theme_thematiques_anchor_links($vars){
|
||||
)
|
||||
);
|
||||
|
||||
$i=0;
|
||||
foreach ($vars["items"] as $nid => $val) {
|
||||
// TODO: display the workflow state ID
|
||||
// TODO: display the workflow state ID
|
||||
$options = array(
|
||||
"class"=>array("anchor"),
|
||||
"fragment"=>$val['alias']
|
||||
"attributes"=>array(
|
||||
"class"=>array("anchor","pos-".$i, $val['wf_state'], 'node-'.$nid),
|
||||
),
|
||||
"fragment"=>$val['alias'],
|
||||
"html"=>true,
|
||||
);
|
||||
$list['items'][] = l($val['title'], '' , $options);
|
||||
$content = $val['title'];
|
||||
if($val["wf_stamp"]){
|
||||
$content .= "<span>" . format_date($val["wf_stamp"], 'custom', "d M Y") . "</span>";
|
||||
}
|
||||
$list['items'][] = l($content, '' , $options);
|
||||
$i++;
|
||||
}
|
||||
|
||||
return theme('item_list', $list);
|
||||
|
||||
Reference in New Issue
Block a user