function custom_pub_entity_base_field_info in Custom Publishing Options 8
Implements hook_entity_base_field_info().
Parameters
EntityTypeInterface $entity_type:
Return value
array
File
- ./
custom_pub.module, line 151
Code
function custom_pub_entity_base_field_info(EntityTypeInterface $entity_type) {
if ($entity_type
->id() === 'node') {
$entities = \Drupal::entityTypeManager()
->getStorage('custom_publishing_option')
->loadMultiple();
$fields = [];
foreach ($entities as $machine_name => $entity) {
$fields[$entity
->id()] = BaseFieldDefinition::create('boolean')
->setLabel(t('@label', [
'@label' => $entity
->label(),
]))
->setDescription(t('@description', [
'@description' => $entity
->getDescription(),
]))
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setDefaultValue(0)
->setDisplayConfigurable('form', TRUE)
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'settings' => [
'display_label' => TRUE,
],
'weight' => 16,
]);
}
return $fields;
}
}