function template_preprocess_aggregator_item

Same name and namespace in other branches
  1. 7.x modules/aggregator/aggregator.pages.inc \template_preprocess_aggregator_item()
  2. 8.9.x core/modules/aggregator/aggregator.theme.inc \template_preprocess_aggregator_item()

Prepares variables for aggregator item templates.

Default template: aggregator-item.html.twig.

By default this function performs special preprocessing to create a separate variable for the title base field. This preprocessing is skipped if:

  • a module makes the field's display configurable via the field UI by means of BaseFieldDefinition::setDisplayConfigurable()
  • AND the additional entity type property 'enable_base_field_custom_preprocess_skipping' has been set using hook_entity_type_build().

Parameters

array $variables: An associative array containing:

  • elements: An array of elements to display in view mode.

File

core/modules/aggregator/aggregator.theme.inc, line 28

Code

function template_preprocess_aggregator_item(&$variables) {
    $item = $variables['elements']['#aggregator_item'];
    // Helpful $content variable for templates.
    foreach (Element::children($variables['elements']) as $key) {
        $variables['content'][$key] = $variables['elements'][$key];
    }
    $variables['url'] = UrlHelper::stripDangerousProtocols($item->getLink());
    // Make title field available separately.  Skip this custom preprocessing if
    // the field display is configurable and skipping has been enabled.
    // @todo https://www.drupal.org/project/drupal/issues/3015623
    //   Eventually delete this code and matching template lines. Using
    //   $variables['content'] is more flexible and consistent.
    $skip_custom_preprocessing = $item->getEntityType()
        ->get('enable_base_field_custom_preprocess_skipping');
    if (!$skip_custom_preprocessing || !$item->getFieldDefinition('title')
        ->isDisplayConfigurable('view')) {
        $variables['title'] = $item->label();
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.