Skip to content

Commit

Permalink
implement #1
Browse files Browse the repository at this point in the history
  • Loading branch information
p-a-s-c-a-l committed Nov 8, 2018
1 parent 2929e01 commit 0a03b84
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions csis_helpers.module
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,39 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\group\Entity\GroupContent;
use Drupal\Core\Form\FormStateInterface;

function csis_helpers_node_view(&$build, $entity, $display){

function csis_helpers_preprocess_group(&$build){
$build['#attached']['drupalSettings']['csisHelpers']['entityinfo'] = csis_helpers_group_entity_info($build['group']);
}

function csis_helpers_preprocess_node(&$build){
$build['#attached']['drupalSettings']['csisHelpers']['entityinfo'] = csis_helpers_node_entity_info($build['node']);
//$build['#attributes']['data-csis'] = json_encode($entityinfo);
}

function csis_helpers_form_node_form_alter (&$form, $form_state, $form_id){
$form['#attached']['drupalSettings']['csisHelpers']['entityinfo'] = csis_helpers_node_entity_info($form_state->GetFormObject()->getEntity());
//$build['#attributes']['data-csis'] = json_encode($entityinfo);
}

function csis_helpers_form_group_form_alter (&$form, $form_state, $form_id){
$form['#attached']['drupalSettings']['csisHelpers']['entityinfo'] = csis_helpers_group_entity_info($form_state->GetFormObject()->getEntity());
//$build['#attributes']['data-csis'] = json_encode($entityinfo);
}

function csis_helpers_node_entity_info(\Drupal\Core\Entity\EntityInterface $entity){
$groupid = array();
$relations = GroupContent::loadByEntity($entity);
foreach ( $relations as $relation) {
$groupid[] = $relation->getGroup()->id();
}
$entityinfo = array('step'=> $entity->id(), 'study'=> $groupid[0]);
$build['#attached']['drupalSettings']['csisHelpers']['entityinfo'] = $entityinfo;
//if(count($groupid) > 0){
// $build['#attached']['drupalSettings']['csisHelpers']['entityinfo']['study'] = $groupid[0];
//}
return $entityinfo;
//$build['#attributes']['data-csis'] = json_encode($entityinfo);
}

function csis_helpers_group_view(&$build,$entity, $display){
function csis_helpers_group_entity_info(\Drupal\Core\Entity\EntityInterface $entity){
$entityinfo = array('step'=> null, 'study'=> $entity->id());
$build['#attached']['drupalSettings']['csisHelpers']['entityinfo'] = $entityinfo;
return$entityinfo;
}

0 comments on commit 0a03b84

Please sign in to comment.