function hook_entity_extra_field_info

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_extra_field_info()
  2. 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_extra_field_info()
  3. 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_extra_field_info()

Exposes "pseudo-field" components on content entities.

Field UI's "Manage fields" and "Manage display" pages let users re-order fields, but also non-field components. For nodes, these include elements exposed by modules through hook_form_alter(), for instance.

Content entities or modules that want to have their components supported should expose them using this hook. The user-defined settings (weight, visible) are automatically applied when entities or entity forms are rendered.

Return value

array The array structure is identical to that of the return value of \Drupal\Core\Entity\EntityFieldManagerInterface::getExtraFields().

See also

hook_entity_extra_field_info_alter()

Related topics

9 functions implement hook_entity_extra_field_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

comment_entity_extra_field_info in core/modules/comment/comment.module
Implements hook_entity_extra_field_info().
contact_entity_extra_field_info in core/modules/contact/contact.module
Implements hook_entity_extra_field_info().
content_moderation_entity_extra_field_info in core/modules/content_moderation/content_moderation.module
Implements hook_entity_extra_field_info().
content_translation_entity_extra_field_info in core/modules/content_translation/content_translation.module
Implements hook_entity_extra_field_info().
entity_test_entity_extra_field_info in core/modules/system/tests/modules/entity_test/entity_test.module
Implements hook_entity_extra_field_info().

... See full list

1 invocation of hook_entity_extra_field_info()
EntityFieldManager::loadExtraFields in core/lib/Drupal/Core/Entity/EntityFieldManager.php
Loads extra fields from cache, or rebuilds them.

File

core/lib/Drupal/Core/Entity/entity.api.php, line 2259

Code

function hook_entity_extra_field_info() {
    $extra = [];
    $module_language_enabled = \Drupal::moduleHandler()->moduleExists('language');
    $description = t('Node module element');
    foreach (NodeType::loadMultiple() as $bundle) {
        // Add also the 'language' select if Language module is enabled and the
        // bundle has multilingual support.
        // Visibility of the ordering of the language selector is the same as on the
        // node/add form.
        if ($module_language_enabled) {
            $configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', $bundle->id());
            if ($configuration->isLanguageAlterable()) {
                $extra['node'][$bundle->id()]['form']['language'] = [
                    'label' => t('Language'),
                    'description' => $description,
                    'weight' => 0,
                ];
            }
        }
        $extra['node'][$bundle->id()]['display']['language'] = [
            'label' => t('Language'),
            'description' => $description,
            'weight' => 0,
            'visible' => FALSE,
        ];
    }
    return $extra;
}

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