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.
array The array structure is identical to that of the return value of \Drupal\Core\Entity\EntityFieldManagerInterface::getExtraFields().
hook_entity_extra_field_info_alter()
function hook_entity_extra_field_info() {
$extra = array();
$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'] = array(
'label' => t('Language'),
'description' => $description,
'weight' => 0,
);
}
}
$extra['node'][$bundle->id()]['display']['language'] = array(
'label' => t('Language'),
'description' => $description,
'weight' => 0,
'visible' => FALSE,
);
}
return $extra;
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!entity.api.php/function/hook_entity_extra_field_info/8.1.x