1

everyone.

From the one side I have an entity class, which stores the values in the $field array and from the other side, I have a custom field for this entity, where I have to pass the value ($timestamp) from the entity.

$fields['lastUpdate']=BaseFieldDefinition::create('last_update') ->setLabel(t('Warnings')) <br> ->setDescription(t('Reference to warnings-content-type')) <br> ->setSetting('target_type', 'warnings_content')  <br> ->setDisplayOptions('view', array(
      'label' => 'above',   
      'format' => 'label',
      'weight' => 15,
    ))
    ->setDisplayOptions('form', array(
      'type' => 'options_buttons',
      'weight' => 15,
    )) ->setCardinality(1000) <br> ->setDisplayConfigurable('form', TRUE) <br> ->setDisplayConfigurable('view', TRUE);

So I think, that I have to extend my Formatter class with the Entity class, so that I am able to use get method of the Entity class.

class Item extends FieldItemBase { ..

public static function getTimestamp() {

date_default_timezone_set("Europa/Paris");

$timestamp = time();

$time = "dfd";

$timestamp = ['#markup' => t($time),
];
return $timestamp;

How can I do that, I know, that time() function returns the current time and I don#t need it.

Thanks in advance.

  • So the question is how can I pass a certain value to formatter – badm Mar 23 '16 at 15:09
  • Yes, I have a special formatter for the 'changed' timestamp. And i need to call it from FieldItemBase class for particular entity – badm Apr 21 '16 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.