Skip to content

Commit 47a1d7d

Browse files
Update Question Display
- Hide asker's municipality and name in Question render. - Remove 'created' field from asklib_answer display. - Hide "title" label in Question view. Note: The hiding is currently implemented through code. Managing the Question display through the admin panel would be preferable.
1 parent 6d08fcd commit 47a1d7d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

asklib.module

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,14 @@ function asklib_preprocess_asklib_question(&$variables) {
399399
'resource' => 'https://www.kirjastot.fi/kysy/' . $variables['elements']['#asklib_question']->id(),
400400
];
401401

402+
/**
403+
* NOTE: These fields should be hidden from Drupal's built-in display management form.
404+
* Currently, asklib does not provide one. Asklib question has only one view mode called "full".
405+
* For future development, we could implement view support for asklib_question and asklib_answer.
406+
*/
407+
unset($variables['question']['municipality']);
408+
unset($variables['question']['user']);
409+
402410
$variables['question']['title_meta'] = [
403411
'#weight' => -1000,
404412
'#theme' => 'rdf_metadata',
@@ -427,6 +435,9 @@ function asklib_preprocess_asklib_answer(&$variables) {
427435
$variables['content'][$key] = $variables['elements'][$key];
428436
}
429437

438+
// See the NOTE in asklib_preprocess_asklib_question about display managment.
439+
unset($variables['content']['created']);
440+
430441
$view = Drupal::entityTypeManager()->getViewBuilder('asklib_question');
431442
$displays = $variables['elements']['#asklib_answer']->getQuestion()->get('displays');
432443
$rendered = $view->viewField($displays, $displays->getFieldDefinition()->getDisplayOptions('view'));

src/QuestionViewBuilder.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public function buildComponents(array &$build, array $entities, array $displays,
3131
$build[$delta]['comments']['#access'] = FALSE;
3232
}
3333
}
34+
35+
// See the NOTE in asklib_preprocess_asklib_question about display managment.
36+
foreach ($build as $delta => $current_build) {
37+
$build[$delta]['title']['#label_display'] = 'hidden';
38+
}
39+
3440
}
3541

3642
/**

0 commit comments

Comments
 (0)