Skip to content

Commit

Permalink
Issue #26: ensure title display is passed to entity template and add …
Browse files Browse the repository at this point in the history
…a theme suggestion
  • Loading branch information
herbdool committed Jan 19, 2022
1 parent 5a9ad10 commit 0ef6335
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion entityreference.module
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,7 @@ function entityreference_field_formatter_view($entity_type, $entity, $field, $in
if (empty($settings['links']) && isset($result[$delta][$target_type][$item[$column]]['links'])) {
$result[$delta][$target_type][$item[$column]]['links']['#access'] = FALSE;
}
$result[$delta][$target_type][$item[$column]]['#theme'] .= '__entityreference';
$depth = 0;
}
break;
Expand Down Expand Up @@ -1560,7 +1561,6 @@ function theme_entityreference_label($vars) {
* @ingroup themeable.
*/
function theme_entityreference_entity_id($vars) {
$settings = $vars['settings'];
$item = $vars['item'];

$output = '';
Expand All @@ -1569,3 +1569,40 @@ function theme_entityreference_entity_id($vars) {

return $output;
}

/**
* Implements hook_preprocess_node().
*/
function entityreference_preprocess_node(&$variables) {
_entityreference_preprocess_set_title_display($variables);
}

/**
* Implements hook_preprocess_file_entity().
*/
function entityreference_preprocess_file_entity(&$variables) {
_entityreference_preprocess_set_title_display($variables);
}

/**
* Implements hook_preprocess_taxonomy_term().
*/
function entityreference_preprocess_taxonomy_term(&$variables) {
_entityreference_preprocess_set_title_display($variables);
}

/**
* Pass title display setting to templates.
*
* If #page is set in the rendered entity reference display mode then pass it to the template.
*
* @param array $variables
*/
function _entityreference_preprocess_set_title_display(&$variables) {
if (!strstr($variables['theme_hook_original'], 'entityreference')) {
return;
}
if (isset($variables['elements']['#page']) && $variables['elements']['#page'] !== NULL) {
$variables['page'] = $variables['elements']['#page'];
}
}

0 comments on commit 0ef6335

Please sign in to comment.