0

I have a custom content entity type. When I create an instance, the first one got the right created time stamp. But starting with the second one, they all have the same created time stamp: as the first one have!

Why is this happening?

Base field definition:

$fields['created'] = BaseFieldDefinition::create('created')
  ->setLabel(t('Created'))
  ->setDescription(t('The time that the entity was created.'))
  ->setReadOnly(TRUE)
  ->setDisplayConfigurable('view', TRUE);

Setter / getter methods:

  /**
   * {@inheritdoc}
   */
  public function getCreatedTime() {
    return $this->get('created')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setCreatedTime($timestamp) {
    $this->set('created', $timestamp);
    return $this;
  }

1 Answer 1

0

I had my php code cached before adding the setCreatedTimemethod to my custom entity. After clearing the cache everything was fine!

So in general: add the setCreatedTime method to your custom entity to make your created timestamp work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.