public static function MicrositeMenuItemOverride::baseFieldDefinitions in Entity Reference Hierarchy 3.x
Same name and namespace in other branches
- 8.2 modules/entity_hierarchy_microsite/src/Entity/MicrositeMenuItemOverride.php \Drupal\entity_hierarchy_microsite\Entity\MicrositeMenuItemOverride::baseFieldDefinitions()
Provides base field definitions for an entity type.
Implementations typically use the class \Drupal\Core\Field\BaseFieldDefinition for creating the field definitions; for example a 'name' field could be defined as the following:
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'));
By definition, base fields are fields that exist for every bundle. To provide definitions for fields that should only exist on some bundles, use \Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions().
The definitions returned by this function can be overridden for all bundles by hook_entity_base_field_info_alter() or overridden on a per-bundle basis via 'base_field_override' configuration entities.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type definition. Useful when a single class is used for multiple, possibly dynamic entity types.
Return value
\Drupal\Core\Field\FieldDefinitionInterface[] An array of base field definitions for the entity type, keyed by field name.
Overrides ContentEntityBase::baseFieldDefinitions
See also
\Drupal\Core\Entity\EntityFieldManagerInterface::getFieldDefinitions()
\Drupal\Core\Entity\FieldableEntityInterface::bundleFieldDefinitions()
File
- modules/
entity_hierarchy_microsite/ src/ Entity/ MicrositeMenuItemOverride.php, line 69
Class
- MicrositeMenuItemOverride
- Defines a class for a content entity to store menu item overrides.
Namespace
Drupal\entity_hierarchy_microsite\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['title'] = BaseFieldDefinition::create('string')
->setLabel(t('Menu link title'))
->setDescription(t('The text to be used for this link in the menu.'))
->setRequired(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'string',
'weight' => -5,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -5,
])
->setDisplayConfigurable('form', TRUE);
$fields['weight'] = BaseFieldDefinition::create('integer')
->setRequired(TRUE)
->setLabel(t('Weight'))
->setDescription(t('Link weight among links in the same menu at the same depth. In the menu, the links with high weight will sink and links with a low weight will be positioned nearer the top.'))
->setDefaultValue(0)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'number_integer',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'number',
'weight' => 20,
]);
$fields['expanded'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Show as expanded'))
->setDescription(t('If selected and this menu link has children, the menu will always appear expanded. This option may be overridden for the entire menu tree when placing a menu block.'))
->setDefaultValue(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'boolean',
'weight' => 0,
])
->setDisplayOptions('form', [
'settings' => [
'display_label' => TRUE,
],
'weight' => 0,
]);
$fields['enabled'] = BaseFieldDefinition::create('boolean')
->setLabel(new TranslatableMarkup('Enabled'))
->setDefaultValue(TRUE)
->setDescription(t('A flag for whether the link should be enabled in menus or hidden.'))
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'boolean',
'weight' => 0,
])
->setDisplayOptions('form', [
'settings' => [
'display_label' => TRUE,
],
'weight' => -1,
]);
$fields['parent'] = BaseFieldDefinition::create('string')
->setLabel(t('Parent plugin ID'))
->setRequired(TRUE)
->setDescription(t('The ID of the parent menu link plugin, or empty string when at the top level of the hierarchy.'));
$fields['target'] = BaseFieldDefinition::create('uuid')
->setRequired(TRUE)
->addConstraint('UniqueField')
->setLabel(new TranslatableMarkup('Target UUID of item to override'));
return $fields;
}