public static function Link::baseFieldDefinitions in Colossal Menu 8
Same name and namespace in other branches
- 2.x src/Entity/Link.php \Drupal\colossal_menu\Entity\Link::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
- src/
Entity/ Link.php, line 185
Class
- Link
- Defines the Link entity.
Namespace
Drupal\colossal_menu\EntityCode
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the Link entity.'))
->setReadOnly(TRUE);
$fields['type'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Type'))
->setDescription(t('The Link type/bundle.'))
->setSetting('target_type', 'colossal_menu_link_type')
->setRequired(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the Link entity.'))
->setReadOnly(TRUE);
$fields['menu'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Menu'))
->setDescription(t('The menu of the Link entity.'))
->setSetting('target_type', 'colossal_menu')
->setRequired(TRUE)
->setReadOnly(TRUE);
$fields['parent'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Parent'))
->setDescription(t('The parent item'))
->setSetting('target_type', 'colossal_menu_link')
->setSetting('handler', 'default');
$fields['title'] = BaseFieldDefinition::create('string')
->setLabel(t('Title'))
->setDescription(t('The text to be used for this link in the menu.'))
->setRequired(TRUE)
->setTranslatable(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -5,
]);
$fields['machine_name'] = BaseFieldDefinition::create('string')
->setLabel(t('Machine name'))
->setDescription(t('Machine name of the menu link'))
->setRequired(TRUE)
->setSetting('max_length', 255)
->addConstraint('UniqueField', [])
->setDisplayOptions('form', [
'type' => 'machine_name',
'weight' => -4,
'settings' => [
'source' => [
'title',
'widget',
0,
'value',
],
'exists' => '\\Drupal\\colossal_menu\\Entity\\Link::loadByMachineName',
],
]);
$fields['show_title'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Show Title'))
->setDescription(t('A flag for whether the title should be shown in menus or hidden.'))
->setDefaultValue(TRUE)
->setDisplayOptions('form', [
'settings' => [
'display_label' => TRUE,
],
'weight' => -4,
]);
$fields['link'] = BaseFieldDefinition::create('link')
->setLabel(t('Link'))
->setSettings([
'link_type' => LinkItemInterface::LINK_GENERIC,
'title' => DRUPAL_DISABLED,
])
->setDisplayOptions('form', [
'type' => 'link_default',
'weight' => -2,
])
->setDisplayConfigurable('form', TRUE);
$fields['enabled'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Enabled'))
->setDescription(t('A flag for whether the link should be enabled in menus or hidden.'))
->setDefaultValue(TRUE)
->setDisplayOptions('form', [
'settings' => [
'display_label' => TRUE,
],
'weight' => -1,
]);
$fields['weight'] = BaseFieldDefinition::create('integer')
->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);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code'))
->setDescription(t('The language code for the Link entity.'))
->setDisplayOptions('form', [
'type' => 'language_select',
'weight' => 10,
])
->setDisplayConfigurable('form', TRUE);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
return $fields;
}