You are here

trait DatexTranslationHack in Datex 8

Hierarchy

File

src/TranslationHack/DatexTranslationHack.php, line 8

Namespace

Drupal\datex\TranslationHack
View source
trait DatexTranslationHack {
  public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
    parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);
    $values =& $form_state
      ->getValue('content_translation');
    if (!$values || !is_array($values) || empty($values['created'])) {
      return;
    }
    $cal = datex_factory();
    if (!$cal) {
      return;
    }
    $created = preg_replace('/ \\+.*?$/', '', $values['created']);
    if (!$cal
      ->parse($created, 'Y-m-d H:i:s')) {
      return;
    }
    $time = $cal
      ->getTimestamp();
    $this->manager
      ->getTranslationMetadata($entity)
      ->setCreatedTime($time);
  }

}

Members