function aggregator_entity_extra_field_info in Drupal 8
Same name and namespace in other branches
- 9 core/modules/aggregator/aggregator.module \aggregator_entity_extra_field_info()
Implements hook_entity_extra_field_info().
By default this function creates pseudo-fields that mask the description and image base fields. These pseudo-fields are omitted 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().
File
- core/
modules/ aggregator/ aggregator.module, line 97 - Used to aggregate syndicated content (RSS, RDF, and Atom).
Code
function aggregator_entity_extra_field_info() {
$extra = [];
$entity_type_manager = \Drupal::entityTypeManager();
$entity_field_manager = \Drupal::service('entity_field.manager');
$extra['aggregator_feed']['aggregator_feed'] = [
'display' => [
'items' => [
'label' => t('Items'),
'description' => t('Items associated with this feed'),
'weight' => 0,
],
'more_link' => [
'label' => t('More link'),
'description' => t('A more link to the feed detail page'),
'weight' => 5,
],
'feed_icon' => [
'label' => t('Feed icon'),
'description' => t('An icon that links to the feed URL'),
'weight' => 6,
],
],
];
// Create Feed image and description pseudo-fields. Skip this 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 lines in FeedViewBuilder. Using
// field formatters is more flexible and consistent.
$skip_custom_preprocessing = $entity_type_manager
->getDefinition('aggregator_feed')
->get('enable_base_field_custom_preprocess_skipping');
$base_field_definitions = $entity_field_manager
->getBaseFieldDefinitions('aggregator_feed');
if (!$skip_custom_preprocessing || !$base_field_definitions['image']
->isDisplayConfigurable('view')) {
$extra['aggregator_feed']['aggregator_feed']['display']['image'] = [
'label' => t('Image'),
'description' => t('The feed image'),
'weight' => 2,
];
}
if (!$skip_custom_preprocessing || !$base_field_definitions['description']
->isDisplayConfigurable('view')) {
$extra['aggregator_feed']['aggregator_feed']['display']['description'] = [
'label' => t('Description'),
'description' => t('The description of this feed'),
'weight' => 3,
];
}
// Create Item description pseudo-field. Skip this 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 lines in ItemViewBuilder. Using
// field formatters is more flexible and consistent.
$skip_custom_preprocessing = $entity_type_manager
->getDefinition('aggregator_item')
->get('enable_base_field_custom_preprocess_skipping');
$base_field_definitions = $entity_field_manager
->getBaseFieldDefinitions('aggregator_item');
if (!$skip_custom_preprocessing || !$base_field_definitions['description']
->isDisplayConfigurable('view')) {
$extra['aggregator_item']['aggregator_item']['display']['description'] = [
'label' => t('Description'),
'description' => t('The description of this feed item'),
'weight' => 2,
];
}
return $extra;
}