function toc_node_entity_base_field_info in TOC Node 8
Implements hook_entity_base_field_info().
File
- ./
toc_node.module, line 139 - This is the main module file for TOC Node.
Code
function toc_node_entity_base_field_info(EntityTypeInterface $entity_type) {
$fields = array();
// Add a 'Highlight' base field to all node types.
if ($entity_type
->id() === 'node') {
$toc_enabled = $entity_type
->getThirdPartySetting('toc_node', 'enabled', 0);
$style = $entity_type
->getThirdPartySetting('toc_node', 'style_default', 'bullets');
$level = $entity_type
->getThirdPartySetting('toc_node', 'level', 2);
$back_to_top_links_defaults = $entity_type
->getThirdPartySetting('toc_node', 'back_to_top_links', 1);
$options_enabled = $entity_type
->getThirdPartySetting('toc_node', 'styles', array(
'none',
'bullets',
'numbers',
));
// Only show options if TOC enabled for this content type.
if (empty($toc_enabled)) {
return;
}
$options_all = array(
'none' => t('No TOC'),
'bullets' => t('Bullets'),
'numbers' => t('Numbered'),
);
$options = array_intersect_key($options_all, array_flip($options_enabled));
$fields['toc_node_style'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Highlight'))
->setDescription(t('Whether or not the node is highlighted.'))
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setDisplayOptions('form', array(
'type' => 'select',
'settings' => array(
'display_label' => TRUE,
),
))
->setDisplayConfigurable('form', TRUE);
}
return $fields;
}