Ejemplo n.º 1
0
 /**
  * Getter for the start timestamp.
  *
  * @param int $index
  *   The index of the field value to be retrieved. Defaults to 0.
  *
  * @return int
  *   The start date as a UNIX timestamp.
  */
 protected function getStartTimeStamp($index = 0)
 {
     $value = $this->fieldItemList->getValue()[$index]['value'];
     $field_def = $this->fieldItemList->getFieldDefinition();
     $field_type = $field_def->getFieldStorageDefinition()->getType();
     if ($field_type == 'datetime') {
         /** @var \Drupal/datetime\Plugin\FieldType\DateTimeItem $field */
         $field = $this->fieldItemList->get($index);
         // Set User's Timezone
         $field->date->setTimezone(timezone_open(drupal_get_user_timezone()));
         // Format to timestamp.
         return $field->date->format('U');
     }
     return (int) $value;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function get($index)
 {
     // The Field API only applies the "field default value" to newly created
     // entities. In the specific case of the "comment status", though, we need
     // this default value to be also applied for existing entities created
     // before the comment field was added, which have no value stored for the
     // field.
     if ($index == 0 && empty($this->list)) {
         $field_default_value = $this->getFieldDefinition()->getDefaultValue($this->getEntity());
         return $this->appendItem($field_default_value[0]);
     }
     return parent::get($index);
 }