I have two custom entities, which use the same boilerplate framework. I can add content to both, but one displays fine (sample) and the other is just blank (chemical).
The twig templates for both are:
module/templates/chemical.html.twig
<div{{ attributes.addClass('chemical') }}>
{% if content %}
{{- content -}}
{% endif %}
</div>
and in module/templates/sample.html.twig
<div{{ attributes.addClass('sample') }}>
{% if content %}
{{- content -}}
{% endif %}
</div>
There are no error messages. Is there something in the entity definition file module/src/Entity/Chemical.php that might be throwing off the display, but still allowing the data to be entered and saved correctly?
Here is the Chemical Entity definition:
<?php
namespace Drupal\lab_system\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\user\UserInterface;
/**
* Defines the Chemical entity.
*
* @ingroup lab_system
*
* @ContentEntityType(
* id = "chemical",
* label = @Translation("Chemical"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\lab_system\ChemicalListBuilder",
* "views_data" = "Drupal\lab_system\Entity\ChemicalViewsData",
*
* "form" = {
* "default" = "Drupal\lab_system\Form\ChemicalForm",
* "add" = "Drupal\lab_system\Form\ChemicalForm",
* "edit" = "Drupal\lab_system\Form\ChemicalForm",
* "delete" = "Drupal\lab_system\Form\ChemicalDeleteForm",
* },
* "access" = "Drupal\lab_system\ChemicalAccessControlHandler",
* "route_provider" = {
* "html" = "Drupal\lab_system\ChemicalHtmlRouteProvider",
* },
* },
* base_table = "chemical",
* admin_permission = "administer chemical entities",
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "smiles" = "smiles",
* "boiling_point" = "boiling_point",
* "tid" = "tid",
* "alternate_tid" = "alternate_tid",
* },
* links = {
* "canonical" = "/admin/structure/lab_system/chemical/{chemical}",
* "add-form" = "/admin/structure/lab_system/chemical/add",
* "edit-form" = "/admin/structure/lab_system/chemical/{chemical}/edit",
* "delete-form" = "/admin/structure/lab_system/chemical/{chemical}/delete",
* "collection" = "/admin/structure/lab_system/chemical",
* },
* field_ui_base_route = "chemical.settings"
* )
*/
class Chemical extends ContentEntityBase implements ChemicalInterface {
/**
* {@inheritdoc}
*/
public function getAlternateNames() {
return $this->get('alternate_names')->values;
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->get('name')->value;
}
/**
* {@inheritdoc}
*/
public function setName($name) {
$this->set('name', $name);
return $this;
}
/**
* {@inheritdoc}
*/
public function getSmiles() {
return $this->get('smiles')->value;
}
/**
* {@inheritdoc}
*/
public function getBoilingPoint() {
return $this->get('boiling_point')->value;
}
/**
* {@inheritdoc}
*/
public function setBoilingPoint($bp) {
$this->set('boiling_point', $bp);
return $this;
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the Chemical entity.'))
->setSettings(array(
'max_length' => 50,
'text_processing' => 0,
))
->setDefaultValue('')
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['alternate_names'] = BaseFieldDefinition::create('string')
->setLabel(t('Alternate Name'))
->setDescription(t('Alternate Names.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setSettings(array(
'max_length' => 50,
'text_processing' => 0,
))
->setDefaultValue('')
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['smiles'] = BaseFieldDefinition::create('string')
->setLabel(t('SMILES'))
->setDescription(t('The SMILES structure.'))
->setSettings(array(
'max_length' => 100,
'text_processing' => 0,
))
->setDefaultValue('')
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['boiling_point'] = BaseFieldDefinition::create('float')
->setLabel(t('Boiling Point'))
->setDescription(t('The boiling point of the compound.'))
->setDefaultValue(TRUE)
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'float',
'weight' => 0,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['tid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Chemical Family'))
->setDescription(t('The family to which this chemical belongs.'))
->setSetting('target_type', 'taxonomy_term')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'integer',
'weight' => 0,
))
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
),
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['alternate_tid'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Chemical Family'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setDescription(t('The family to which this chemical belongs.'))
->setSetting('target_type', 'taxonomy_term')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'integer',
'weight' => 0,
))
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
),
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}
}