public function JobItem::dataItemRevert

Reverts data item translation to the latest existing revision.

Parameters

array $key: Data item key that should be reverted.

Return value

bool Result of the revert action.

Overrides JobItemInterface::dataItemRevert

File

src/Entity/JobItem.php, line 783

Class

JobItem
Entity class for the tmgmt_job_item entity.

Namespace

Drupal\tmgmt\Entity

Code

public function dataItemRevert(array $key) {
  $data = $this
    ->getData($key);
  if (!empty($data['#translation']['#text_revisions'])) {
    $prev_revision = end($data['#translation']['#text_revisions']);
    $data['#translation']['#text_revisions'][] = array(
      '#text' => $data['#translation']['#text'],
      '#timestamp' => $data['#translation']['#timestamp'],
      '#origin' => $data['#translation']['#origin'],
    );
    $data['#translation']['#text'] = $prev_revision['#text'];
    $data['#translation']['#origin'] = $prev_revision['#origin'];
    $data['#translation']['#timestamp'] = $prev_revision['#timestamp'];
    $this
      ->updateData($key, $data);
    $this
      ->addMessage('Translation for @key reverted to the latest version.', array(
      '@key' => $key[0],
    ));
    return TRUE;
  }
  return FALSE;
}